Skip to content

feat(explorer): mark failed history runs and split UNION scopes in column usage - #1542

Merged
debba merged 3 commits into
TabularisDB:mainfrom
shu-chen-dot-ca:feat-1479-followup
Nov 19, 2026
Merged

debba merged 3 commits into
TabularisDB:mainfrom
shu-chen-dot-ca:feat-1479-followup

Conversation

@shu-chen-dot-ca

@shu-chen-dot-ca shu-chen-dot-ca commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #1479, with the points @debba listed there as follow-ups (7, 3 and the component tests from 6, repeated in the approving review).

What changed

  • Failed history runs (utils/columnUsageCollector.ts, ColumnUsageModal): history evidence now keeps the entry's status and error. A failed run gets a "Failed run" tag in the panel, with its error message under the title. The copied summary only adds the tag, not the error text, since errors often quote values (duplicate key value (email)=(...)), the same reason the summary never has raw SQL. The confidence is unchanged: the SQL still says what it says about the column.
  • UNION / INTERSECT / EXCEPT / MINUS (utils/columnUsage.ts): computeScopes now starts a sibling query level at a set operator, with the same parent, so each side resolves unqualified columns against its own tables. SELECT customer_id FROM public.orders UNION SELECT customer_id FROM public.archive now gives one parsed match instead of two several-tables.
    • A word counts as a set operator only where a query follows it (isSetOperatorAt): SELECT, WITH, VALUES or TABLE, after an optional ALL/DISTINCT and any opening parentheses. So minus as a column or alias name (PostgreSQL, MySQL, SQLite) and BigQuery/ClickHouse * EXCEPT (col) don't split the query. The same check is used for the wildcard's select list, the FROM-list end and the alias check.
    • Only the level's own frame splits (the statement or a (SELECT / (WITH parenthesis), so a set operator inside function arguments or other parentheses does not. Correlated references from either side still climb to the enclosing query.
    • FROM ((SELECT ...) UNION (SELECT ...)) d was read as a parenthesised join group, so d was never bound and d.customer_id came out as unresolved-qualifier. A parenthesis whose first inner query is followed by a set operator is now a derived table, like ((SELECT ...)) d.
    • An ORDER BY after the last side still resolves against that side's tables only.
  • New string columnUsage.failedRun in all 13 locales.

Tests

  • tests/components/modals/ColumnUsageModal.test.tsx (new): initial focus on Close, Stop between lookups (remaining sources cancelled, their lookups never called), an unexpected collector failure settling every source as failed and recovering on Search again, Open going to the referenced table in the key's schema, Open in editor without running the query, and the failed-run tag with its error on only the failed entry.
  • SidebarColumnItem.test.tsx: the column menu opens with Show Usage when canManage is false (without Modify/Delete), opens the panel for that column, table, schema and database, and has no menu on a view column.
  • columnUsage.test.ts:
    • UNION, UNION ALL, INTERSECT, EXCEPT and Oracle MINUS, both orders of the sides, a join inside one side (still several-tables), a UNION inside a subquery and inside a derived table with and without parentheses per side, a correlated reference from the second side, and a parenthesised join group still read as one.
    • Set-operator words that start no query: SELECT customer_id, minus FROM public.orders (PostgreSQL, MySQL, SQLite), SELECT customer_id, * EXCEPT (secret) FROM public.orders, * EXCEPT (secret) and * EXCEPT secret alone (uncertain wildcard), and minus as a table alias. UNION DISTINCT, EXCEPT ALL, UNION (SELECT, UNION ((SELECT and UNION WITH still split.
  • columnUsageCollector.test.ts: status and error on history evidence, and the summary tagging failed runs without the error text.
  • RotateCw was missing from the lucide-react mock in tests/setup.ts, which the modal test needed.

The new tests for the failed tag, UNION scopes and set-operator words fail without the change; the others cover behaviour that already worked.

Checks: pnpm run typecheck && pnpm run lint && pnpm run lint:theme && pnpm run format:check && pnpm run web:boundaries && pnpm run web:packaging && pnpm run web:docs && pnpm run web:manual-parity && pnpm run test:contrast && pnpm run build && pnpm exec vitest --config packages/web-ui/vitest.config.ts run --maxWorkers=2 pass: 578 files, 9459 tests.

Manual check with Tabularis Web (this branch's dist on a nightly binary) against SQLite, with a history holding a failed query and a UNION over orders and archive; screenshots of orders.customer_id below.

GitNexus: upstream impact of computeScopes reports HIGH because it reaches three clusters, but they are buildModel, analyseStatement and findColumnReferences in the same file, used only by the column usage collector. collectColumnUsage, formatColumnUsageSummary and ColumnUsageModal are LOW.

Screenshots

Before After
before after

@@ -462,6 +468,11 @@ export function isUsageComplete(result: ColumnUsageResult): boolean {
type Translate = (key: string, options?: Record<string, unknown>) => string;

/** The qualified name shown for the target, e.g. `public.orders.customer_id`. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Misplaced doc comment

isFailedRun was inserted between the JSDoc for formatUsageTarget and the function itself, so this comment now sits above isFailedRun and formatUsageTarget has none. Move isFailedRun (and its comment) above this line.

@kilo-code-bot

kilo-code-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files, incremental)
  • packages/web-ui/src/utils/columnUsage.ts
  • packages/web-ui/src/utils/columnUsageCollector.ts (previous JSDoc misplacement fixed)
  • packages/web-ui/tests/utils/columnUsage.test.ts
Previous Review Summary (commit 55eeb46)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 55eeb46)

Status: 1 Issue Found | Recommendation: Merge after optional fix

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/web-ui/src/utils/columnUsageCollector.ts 470 isFailedRun was inserted between the formatUsageTarget JSDoc and its function, so the comment is now misplaced
Files Reviewed (21 files)
  • packages/web-ui/src/components/modals/ColumnUsageModal.tsx
  • packages/web-ui/src/utils/columnUsage.ts
  • packages/web-ui/src/utils/columnUsageCollector.ts - 1 issue
  • 13 locale files (failedRun string added)
  • 5 test and setup files

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5.5 · Input: 248 · Output: 793 · Cached: 141.7K

Review guidance: REVIEW.md from base branch main

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shu-chen-dot-ca for picking these up so quickly. Splitting the UNION sides into sibling levels with the same parent is a neat fit for how computeScopes already works, and the ((SELECT ...) UNION (SELECT ...)) d fix plus the new ColumnUsageModal tests close the gaps I mentioned in #1479. I ran the branch locally: tests, typecheck and lint pass, and a UNION over orders and archive now gives one parsed match per side.

One thing needs to change before I merge. The split in computeScopes fires on any UNION/INTERSECT/EXCEPT/MINUS word, even when no query follows it. Two cases that are parsed on main now return no match at all:

  • SELECT customer_id, minus FROM public.orders: minus is a legal unquoted column name in PostgreSQL, MySQL and SQLite (MINUS is only a set operator in Oracle).
  • SELECT customer_id, * EXCEPT (secret) FROM public.orders: the * EXCEPT (...) select list in BigQuery, ClickHouse and Databricks.

In both, FROM orders ends up in the new level, so customer_id has no table to resolve against. Because there are relations, the textual fallback doesn't kick in either, and the view or history entry silently drops out of the panel. For a panel people check before dropping or renaming a column, a missed hit is worse than an uncertain one. Splitting only when a query actually follows the operator (SELECT, WITH, VALUES, TABLE or (SELECT/(WITH, after an optional ALL/DISTINCT) should fix both. Please add these two statements as regression tests.

Two small things while you're there:

  • isFailedRun landed under the doc comment of formatUsageTarget in columnUsageCollector.ts, so one function has two doc comments and the other none.
  • An ORDER BY customer_id after the last side counts as a parsed match only for that side's table. Not a big deal, but worth knowing if you touch that code again.

@shu-chen-dot-ca

Copy link
Copy Markdown
Contributor Author

Thanks @debba, good catch. Pushed 594e04d and 6386691:

  • Set operators: a new isSetOperatorAt treats UNION/INTERSECT/EXCEPT/MINUS as one only when a query follows (SELECT, WITH, VALUES or TABLE, after an optional ALL/DISTINCT and any opening parentheses). computeScopes splits only there.
    • Other places read the same words and had the same problem: the wildcard's end-of-select scan, the walk back over select items, the FROM-list end and the alias check. They all use the helper now.
    • Both of your statements are parsed again. Two related cases are fixed too:
      • SELECT * EXCEPT (secret) FROM public.orders now gives uncertain:wildcard. It was missed on main as well.
      • In FROM public.orders minus, minus now binds as an alias. It was unresolved-qualifier before.
  • Doc comment: isFailedRun now sits above formatUsageTarget's doc comment.

The new test splits only where a query follows UNION, INTERSECT, EXCEPT or MINUS covers:

  • your two statements, with minus on PostgreSQL, MySQL and SQLite;
  • * EXCEPT (secret) and * EXCEPT secret, and the minus alias;
  • forms that should still split: UNION DISTINCT, EXCEPT ALL, UNION (SELECT, UNION ((SELECT and UNION WITH.

It fails on 55eeb46.

The ORDER BY after the last side is unchanged: it still resolves against that side's tables only.

Official frontend checks (pnpm run typecheck && pnpm run lint && pnpm run lint:theme && pnpm run format:check && pnpm run web:boundaries && pnpm run web:packaging && pnpm run web:docs && pnpm run web:manual-parity && pnpm run test:contrast && pnpm run build && pnpm exec vitest --config packages/web-ui/vitest.config.ts run --maxWorkers=2) pass: 578 files, 9459 tests. One earlier run on a loaded machine failed PluginTriggerSqlEditor.test.tsx (debounce timing). That file passed 5 of 5 runs on its own, and the full run passed when repeated.

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Shu Chen. I like that you reused the same set-operator check in the scope splitter, the wildcard scan, and the alias parser. The new tests cover both cases I tripped over: a column named minus and a BigQuery-style * EXCEPT (...). The doc comment is back with formatUsageTarget, too. I ran the four changed test files locally and all 87 tests passed.

Approved. One follow-up: a trailing ORDER BY on the combined result is still attributed to the last UNION arm. It would be good to add a regression test and handle that separately. I'll keep this open until my manual pass.

@debba
debba merged commit d1899de into TabularisDB:main Nov 19, 2026
12 checks passed
@shu-chen-dot-ca
shu-chen-dot-ca deleted the feat-1479-followup branch November 19, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants