Skip to content

Read a column over an earlier alias of its name - #10

Merged
IL-William merged 1 commit into
masterfrom
fix/alias-shadowed-by-column-master
Oct 11, 2026
Merged

IL-William merged 1 commit into
masterfrom
fix/alias-shadowed-by-column-master

Conversation

@IL-William

@IL-William IL-William commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Patch 11 of the engine fork that collin pins (dbt-collin decision 0028). An identifier in a select list that a source of the FROM is known to have is now read as that column, even when an earlier item gives an alias of that name.

Until now the earlier alias always won:

  • SELECT a AS b, b AS c FROM p, where p has b, came out with c reading p.a.

Snowflake and DuckDB give c the value of p.b. On Snowflake, select a as b, b as c from (select 1 as a, 2 as b) returns c = 2. The column wins over the alias, in the select list as in GROUP BY. BigQuery reads no alias of its own select list at all.

The change

  • resolve_lateral_alias_sources now leaves an identifier as a column reference when candidate_tables_for_column finds a source in scope with that column, through CTE and derived-table columns or the schema handed in.
  • Where no source is known to have it, the alias is the only name in sight and is read through as before. So a query with no schema behaves as it did.
  • candidate_tables_for_column becomes pub(super) so the select analyzer can ask.

Tests

  • a_column_wins_over_an_earlier_alias_of_its_name, on Snowflake and DuckDB:
    • a bare read;
    • a read inside a function;
    • a read beside another column;
    • a read through a CTE;
    • an alias no source has, still read through.
  • It fails without the patch: c reads p.a.
  • 2628 tests of flowscope-core pass, and cargo fmt --all --check is clean.

Measured through collin

Project Effect
3507 model Snowflake project cache identical, --indirect too, dump identical
Shopify (DuckDB) one edge moves, as the SQL says: country as country_name beside country_code as country now reads country
Cal-ITP (BigQuery) 12 parsed edges lost and 6 gained in 7 models. Each was read in the SQL, and each now follows the column: a swap of two names, and columns redefined by a COALESCE or a CASE and read again in a hash, a window key or a later expression
lineage-library catalogue_entries gives its hand-written lineage: both marks of IL-William/dbt-collin#29 go

Nothing goes to pondpilot/flowscope.

🤖 Generated with Claude Code

https://claude.ai/code/session_0144SufcRMDVctcvHmcb1665

A name in a select list that an earlier item gives as an alias was always
read as that alias, even where a source of the FROM has a column of that
name.

    SELECT a AS b, b AS c FROM p          -- p has b

c came out reading p.a. Snowflake and DuckDB give c the value of p.b:
the column wins over the alias, in the select list as in GROUP BY. And
BigQuery reads no alias of its own select list at all.

An identifier a source in scope is known to have now stays a column
reference, alone or inside an expression. Where no source is known to
have it, the alias is the only name in sight and is read through as
before.

Claude-Session: https://claude.ai/code/session_0144SufcRMDVctcvHmcb1665

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@IL-William
IL-William merged commit 01a4f35 into master Oct 11, 2026
8 checks passed
@IL-William
IL-William deleted the fix/alias-shadowed-by-column-master branch October 11, 2026 10:20
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.

1 participant