Repository navigation
fix: column names at the edges of the column answer - #1754
ralphstodomingo wants to merge 1 commit into
Conversation
A `_N` a parent passes on or the SQL writes stays a column; only a COLUMNS() item's own alias is a template; a name repeated beside `*` doesn't settle; Postgres and Redshift name a cast after its column; DuckDB's repeated outputs get `_1` names. The text line reads "not traced (no sign either way)". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VEmKQwEiHMwQ7BdwgPo9sb
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait...
|
|
Review log: claims and residuals Claims (each can be violated by a concrete trace):
Disclosed residuals (accepted; instances are not findings):
|
|
@codex review against the numbered claims and the disclosed residuals in the review-log comment on this PR: report only a reproducible trace that violates a numbered claim. Instances of the disclosed residuals are not findings. A round with no claim violation ends review. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
5 issues found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/opencode/src/altimate/native/dbt/project-lineage.ts">
<violation number="1" location="packages/opencode/src/altimate/native/dbt/project-lineage.ts:110">
P2: `namesItsOutputs` no longer rejects engine-made names, so a SELECT with an unaliased expression can now be treated as settled. Restore the `engineMade` rejection, or show that `extractOutputColumns` never returns `_N` for unaliased expressions. Otherwise `missingColumn` can wrongly report the expression's column as absent.</violation>
<violation number="2" location="packages/opencode/src/altimate/native/dbt/project-lineage.ts:123">
P2: `selectItems` ends the SELECT list early at a quoted identifier whose name is a keyword. Only parentheses and commas are masked inside quotes, so `"order"` or `"from"` still matches the terminator test. Mask the whole quoted token instead.</violation>
<violation number="3" location="packages/opencode/src/altimate/native/dbt/project-lineage.ts:160">
P2: `itemName` misses valid aliases written without `AS`, so `select *, val id` is treated as settled despite the duplicate output being warehouse-renamed. Recognize bare aliases before settling a star projection.</violation>
<violation number="4" location="packages/opencode/src/altimate/native/dbt/project-lineage.ts:185">
P2: This treats every `COLUMNS(...) AS alias` as a template, so ordinary aliases are dropped from the model's real columns. Only aliases containing a replacement marker such as `\\0` should be filtered as templates.</violation>
<violation number="5" location="packages/opencode/src/altimate/native/dbt/project-lineage.ts:658">
P2: The duplicate-output guard ignores qualified stars such as `f.*`, even though `selectsStar` recognizes them. Check star items through `itemName` so `select f.*, val as id` remains unsettled when `id` is brought in by the parent.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| * top-level commas, from literal- and comment-stripped SQL; [] when there is none. | ||
| */ | ||
| export function selectItems(stripped: string): string[] { | ||
| const text = stripped.replace(new RegExp(QUOTED, "g"), (q) => q.replace(/[(),]/g, " ")) |
There was a problem hiding this comment.
P2: selectItems ends the SELECT list early at a quoted identifier whose name is a keyword. Only parentheses and commas are masked inside quotes, so "order" or "from" still matches the terminator test. Mask the whole quoted token instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/opencode/src/altimate/native/dbt/project-lineage.ts, line 123:
<comment>`selectItems` ends the SELECT list early at a quoted identifier whose name is a keyword. Only parentheses and commas are masked inside quotes, so `"order"` or `"from"` still matches the terminator test. Mask the whole quoted token instead.</comment>
<file context>
@@ -102,10 +102,106 @@ function engineMade(name: string, stripped: string): boolean {
+ * top-level commas, from literal- and comment-stripped SQL; [] when there is none.
+ */
+export function selectItems(stripped: string): string[] {
+ const text = stripped.replace(new RegExp(QUOTED, "g"), (q) => q.replace(/[(),]/g, " "))
+ let depth = 0
+ let start = -1
</file context>
| const text = stripped.replace(new RegExp(QUOTED, "g"), (q) => q.replace(/[(),]/g, " ")) | |
| const text = stripped.replace(new RegExp(QUOTED, "g"), (q) => " ".repeat(q.length)) |
| * unaliased expression or a `*`, so an empty list doesn't settle; neither does a repeated name, which the | ||
| * warehouse renames. | ||
| */ | ||
| function namesItsOutputs(outputs: string[]): boolean { |
There was a problem hiding this comment.
P2: namesItsOutputs no longer rejects engine-made names, so a SELECT with an unaliased expression can now be treated as settled. Restore the engineMade rejection, or show that extractOutputColumns never returns _N for unaliased expressions. Otherwise missingColumn can wrongly report the expression's column as absent.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/opencode/src/altimate/native/dbt/project-lineage.ts, line 110:
<comment>`namesItsOutputs` no longer rejects engine-made names, so a SELECT with an unaliased expression can now be treated as settled. Restore the `engineMade` rejection, or show that `extractOutputColumns` never returns `_N` for unaliased expressions. Otherwise `missingColumn` can wrongly report the expression's column as absent.</comment>
<file context>
@@ -102,10 +102,106 @@ function engineMade(name: string, stripped: string): boolean {
+ * unaliased expression or a `*`, so an empty list doesn't settle; neither does a repeated name, which the
+ * warehouse renames.
+ */
+function namesItsOutputs(outputs: string[]): boolean {
const names = outputs.map((name) => name.toLowerCase())
- return names.length > 0 && new Set(names).size === names.length && !names.some((name) => engineMade(name, stripped))
</file context>
| /** Whether a bare `*` sits beside an output that repeats a name the star brings in (`select *, val as id`). */ | ||
| private renamesBesideStar(id: string, stripped: string): boolean { | ||
| const items = selectItems(stripped) | ||
| if (!items.some((item) => /^\*(?:\s|$)/.test(item))) return false |
There was a problem hiding this comment.
P2: The duplicate-output guard ignores qualified stars such as f.*, even though selectsStar recognizes them. Check star items through itemName so select f.*, val as id remains unsettled when id is brought in by the parent.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/opencode/src/altimate/native/dbt/project-lineage.ts, line 658:
<comment>The duplicate-output guard ignores qualified stars such as `f.*`, even though `selectsStar` recognizes them. Check star items through `itemName` so `select f.*, val as id` remains unsettled when `id` is brought in by the parent.</comment>
<file context>
@@ -541,14 +643,24 @@ export class ProjectLineage {
+ /** Whether a bare `*` sits beside an output that repeats a name the star brings in (`select *, val as id`). */
+ private renamesBesideStar(id: string, stripped: string): boolean {
+ const items = selectItems(stripped)
+ if (!items.some((item) => /^\*(?:\s|$)/.test(item))) return false
+ const brought = new Set(this.parents(id).flatMap((p) => [...(this.settledColumns(p) ?? [])]))
+ const explicit = items.map(itemName).filter((name): name is string => !!name && name !== "*")
</file context>
| if (!items.some((item) => /^\*(?:\s|$)/.test(item))) return false | |
| if (!items.some((item) => itemName(item) === "*")) return false |
| /** A SELECT item's output name when the SQL gives one (`x as name`, a bare `t.col`), `*` for a star, else null. */ | ||
| export function itemName(item: string): string | null { | ||
| if (/^(?:[\w$]+\.)*\*(?:\s|$)/.test(item)) return "*" | ||
| const as = new RegExp(`\\s+as\\s+(${QUOTED}|[\\w$]+)$`, "i").exec(item) |
There was a problem hiding this comment.
P2: itemName misses valid aliases written without AS, so select *, val id is treated as settled despite the duplicate output being warehouse-renamed. Recognize bare aliases before settling a star projection.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/opencode/src/altimate/native/dbt/project-lineage.ts, line 160:
<comment>`itemName` misses valid aliases written without `AS`, so `select *, val id` is treated as settled despite the duplicate output being warehouse-renamed. Recognize bare aliases before settling a star projection.</comment>
<file context>
@@ -102,10 +102,106 @@ function engineMade(name: string, stripped: string): boolean {
+/** A SELECT item's output name when the SQL gives one (`x as name`, a bare `t.col`), `*` for a star, else null. */
+export function itemName(item: string): string | null {
+ if (/^(?:[\w$]+\.)*\*(?:\s|$)/.test(item)) return "*"
+ const as = new RegExp(`\\s+as\\s+(${QUOTED}|[\\w$]+)$`, "i").exec(item)
+ if (as) return unquoteName(as[1]!)
+ const bare = new RegExp(`^(?:(?:${QUOTED}|[\\w$]+)\\.)*(${QUOTED}|[\\w$]+)$`).exec(item)
</file context>
| else if (stripped[i] === ")" && --depth === 0) break | ||
| } | ||
| const alias = new RegExp(`^\\s*as\\s+(${QUOTED}|[\\w$]+)`, "i").exec(stripped.slice(i + 1)) | ||
| if (alias) out.add(unquoteName(alias[1]!)) |
There was a problem hiding this comment.
P2: This treats every COLUMNS(...) AS alias as a template, so ordinary aliases are dropped from the model's real columns. Only aliases containing a replacement marker such as \\0 should be filtered as templates.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/opencode/src/altimate/native/dbt/project-lineage.ts, line 185:
<comment>This treats every `COLUMNS(...) AS alias` as a template, so ordinary aliases are dropped from the model's real columns. Only aliases containing a replacement marker such as `\\0` should be filtered as templates.</comment>
<file context>
@@ -102,10 +102,106 @@ function engineMade(name: string, stripped: string): boolean {
+ else if (stripped[i] === ")" && --depth === 0) break
+ }
+ const alias = new RegExp(`^\\s*as\\s+(${QUOTED}|[\\w$]+)`, "i").exec(stripped.slice(i + 1))
+ if (alias) out.add(unquoteName(alias[1]!))
+ }
+ return out
</file context>

Issue for this PR
Closes #1753
Type of change
What does this PR do?
Follow-up to #1710, from its last review: column names at the edges of
impact_analysis's column answer anddbt_lineage._Na parent passes on, or that the SQL writes as an alias, stays a column.COLUMNS(...) AS "…"item's own alias is a template.*doesn't settle._1names.Nothing is reported unaffected, as before.
How did you verify your code works?
Each shape has a test that fails on main. The demo project's answer is unchanged: 11 carry it, 28 may carry it, of 39.
Cost side effects
None (local manifest only).
Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01VEmKQwEiHMwQ7BdwgPo9sb
Summary by cubic
Fixes how the column answer identifies column names at its edges so tracing follows real columns instead of dropping them or following engine-generated placeholder names. Closes #1753.
_Na parent passes on, or the SQL writes as an alias, stays a column; only aCOLUMNS(...) AS "…"item's own alias is treated as a template.*no longer settles as a column of the model._1names.Written for commit 755204d. Summary will update on new commits.
Summary by CodeRabbit