Repository navigation
feat(explorer): mark failed history runs and split UNION scopes in column usage - #1542
Conversation
| @@ -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`. */ | |||
There was a problem hiding this comment.
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.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files, incremental)
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
Issue Details (click to expand)SUGGESTION
Files Reviewed (21 files)
Reviewed by claude-sonnet-5.5 · Input: 248 · Output: 793 · Cached: 141.7K Review guidance: REVIEW.md from base branch |
debba
left a comment
There was a problem hiding this comment.
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:minusis 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:
isFailedRunlanded under the doc comment offormatUsageTargetincolumnUsageCollector.ts, so one function has two doc comments and the other none.- An
ORDER BY customer_idafter 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.
|
Thanks @debba, good catch. Pushed 594e04d and 6386691:
The new test
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 ( |
debba
left a comment
There was a problem hiding this comment.
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.
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
utils/columnUsageCollector.ts,ColumnUsageModal): history evidence now keeps the entry'sstatusanderror. 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.utils/columnUsage.ts):computeScopesnow 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.archivenow gives one parsed match instead of twoseveral-tables.isSetOperatorAt): SELECT, WITH, VALUES or TABLE, after an optional ALL/DISTINCT and any opening parentheses. Sominusas 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.(SELECT/(WITHparenthesis), 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 ...)) dwas read as a parenthesised join group, sodwas never bound andd.customer_idcame out asunresolved-qualifier. A parenthesis whose first inner query is followed by a set operator is now a derived table, like((SELECT ...)) d.ORDER BYafter the last side still resolves against that side's tables only.columnUsage.failedRunin 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 whencanManageis 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: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.SELECT customer_id, minus FROM public.orders(PostgreSQL, MySQL, SQLite),SELECT customer_id, * EXCEPT (secret) FROM public.orders,* EXCEPT (secret)and* EXCEPT secretalone (uncertain wildcard), andminusas a table alias.UNION DISTINCT,EXCEPT ALL,UNION (SELECT,UNION ((SELECTandUNION WITHstill split.columnUsageCollector.test.ts:statusanderroron history evidence, and the summary tagging failed runs without the error text.RotateCwwas missing from thelucide-reactmock intests/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=2pass: 578 files, 9459 tests.Manual check with Tabularis Web (this branch's
diston a nightly binary) against SQLite, with a history holding a failed query and a UNION overordersandarchive; screenshots oforders.customer_idbelow.GitNexus: upstream
impactofcomputeScopesreports HIGH because it reaches three clusters, but they arebuildModel,analyseStatementandfindColumnReferencesin the same file, used only by the column usage collector.collectColumnUsage,formatColumnUsageSummaryandColumnUsageModalare LOW.Screenshots