Skip to content

fix: column names at the edges of the column answer - #1754

Open
ralphstodomingo wants to merge 1 commit into
mainfrom
fix/1753-column-answer-name-edges
Open

ralphstodomingo wants to merge 1 commit into
mainfrom
fix/1753-column-answer-name-edges

Conversation

@ralphstodomingo

@ralphstodomingo ralphstodomingo commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #1753

Type of change

  • Bug fix

What does this PR do?

Follow-up to #1710, from its last review: column names at the edges of impact_analysis's column answer and dbt_lineage.

  • A _N a parent passes on, or that the SQL writes as an alias, stays a column.
  • Only a COLUMNS(...) AS "…" item's own alias is a template.
  • A name repeated beside * doesn't settle.
  • Postgres and Redshift name an unaliased cast after its column, so the trace goes on.
  • DuckDB's repeated outputs get its _1 names.
  • The text line reads "K of them not traced (no sign either way)".

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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

🤖 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.

  • A _N a parent passes on, or the SQL writes as an alias, stays a column; only a COLUMNS(...) AS "…" item's own alias is treated as a template.
  • A name repeated beside a bare * no longer settles as a column of the model.
  • Postgres and Redshift name an unaliased cast after its column, so a cast of a real column traces through, and DuckDB's repeated outputs get their _1 names.
  • The summary text now reads "not traced (no sign either way)" for models with no trace either way.

Written for commit 755204d. Summary will update on new commits.

View guided diff Turn on auto-fix

Summary by CodeRabbit

  • Bug Fixes
    • Improved column lineage results for repeated output names, aliases, wildcard selections, and casts across supported database engines.
    • Corrected handling of columns passed through from parent models, helping preserve accurate tracing when names overlap.
    • Clarified the description of models with no tracing information: “not traced (no sign either way).”

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
@ralphstodomingo ralphstodomingo self-assigned this Nov 16, 2026
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

CodeRabbit ASCII loading animation

Currently processing new changes in this PR. This may take a few minutes, please wait...

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 543c013e-b15d-48b6-8013-15ecb1e2ce68
Commits

Reviewing files that changed from the base of the PR and between 6b01e20 and 755204d.

Files selected for processing: 3

  • packages/opencode/src/altimate/native/dbt/column-answer.ts
  • packages/opencode/src/altimate/native/dbt/project-lineage.ts
  • packages/opencode/test/altimate/column-answer.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ralphstodomingo

Copy link
Copy Markdown
Contributor Author

Review log: claims and residuals

Claims (each can be violated by a concrete trace):

  • C1. Nothing past the edited model is reported unaffected: every model-level descendant (upstream: ancestor) that the traced edges don't reach is in may_carry exactly once, as on main.
  • C2. A _N or _col_N name that a parent passes on under the same name, or that the SQL itself writes as an alias, is a column of the model and keeps its edge. Only the engine's own name for an unaliased expression is left out.
  • C3. Only the alias of a COLUMNS(...) AS "…" item is taken as a template. Any other name with a backslash and a digit is a column.
  • C4. A bare * beside an output that repeats a name the star brings in (select *, val as id), or that repeats itself, doesn't settle the model, so the warehouse's renamed column never gets a "has no column" error.
  • C5. On Postgres and Redshift, an unaliased cast of a column (amount::numeric, cast(t.amount as numeric)) is named after that column, and the trace goes on through it. On other dialects the engine's _col_N label stays.
  • C6. On DuckDB, a SELECT list's repeated outputs add DuckDB's names (val_1, val_2) to the model's columns, so a select * child lists them. Other dialects are unchanged.
  • C7. For a model with none of these shapes, dbt_lineage, column_reach and column_answer give the same answer as main (bc8025b).

Disclosed residuals (accepted; instances are not findings):

  • R1. The repeat check beside a star applies to a bare * only, not to t.*, since the text check maps no alias to its relation.
  • R2. On DuckDB, column_answer still says a join's second val lands in val (the engine's edge), though the model's columns list val_1.
  • R3. Postgres and Redshift naming covers a cast of a column only; other unaliased expressions keep the _col_N label.
  • R4. The SELECT list is read from text: the first SELECT outside parentheses, split at top-level commas.

@ralphstodomingo

Copy link
Copy Markdown
Contributor Author

@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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T04:55:51.815656Z 755204d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 755204dac6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@ralphstodomingo
ralphstodomingo marked this pull request as ready for review November 16, 2026 05:57

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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, " "))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>
Suggested change
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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>
Suggested change
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]!))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: column answer mishandles some column names at the edges

1 participant