Skip to content

fix(rules): read relation markers as tables in custom-rule syntax trees - #1370

Closed
kvlonge wants to merge 1 commit into
mainfrom
fix/sql-tree-placeholder-relations
Closed

kvlonge wants to merge 1 commit into
mainfrom
fix/sql-tree-placeholder-relations

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Why

Compiled query_sql keeps relation markers such as __ref("orders"). Snowflake does not accept a bare function call in FROM, and newer SQLQuack Snowflake parsers refuse it too ("Expected TABLE( ) around a table function"). Custom-rule syntax trees (SqlDocument) over Snowflake models with references would then fail, as would the compile benchmark's statistics, which read the same trees. This must land before a newer SQLQuack pin.

Changes

  • New shared helper sqlbuild_analysis::relation_markers::main::markers_as_names. It writes each marker call in code as __sqb_<index>, padded with spaces and the call's own line breaks so later text keeps its line and column. It returns the calls (function, name) by index. Calls in comments and quoted text are left alone. It starts from the SQL-test planning template's helper, so both share one reading.
  • sql_tree_nodes, and so SqlDocument, parses through it for every dialect. Marker calls now read as table nodes rather than function calls.
  • The rules crate's dialect lexical syntax moves to sqlbuild_sqltext::sql_scan::main::dialect_lexical_syntax, so query facts and syntax trees share one mapping.
  • Compiled output is unchanged; only the text that syntax trees parse changes.

Verification

  • Unit tests: positions, multi-line calls, comments and quoted text, non-ASCII names, two-name __dbt_ref, calls left alone. A Snowflake sql_tree case puts nodes after markers on the same line.
  • E2E: a custom rule over a Snowflake model's expanded query with __ref, through sqb compile.
  • At SQLQuack 19c51fa2: without the helper, the Snowflake sql_tree case fails with the error above; with it, it passes. The E2E and SqlDocument tests pass (9/9). The varied 1,000-model statistics match the current pin: 999 shapes, 175 array models, 340 window models.
  • make check-ci

DuckShop: no new case. Its models already use __ref/__source; the gap was the Snowflake tree parse, covered by the unit and E2E cases.

Compiled query_sql keeps relation markers such as __ref("orders"). Snowflake
does not accept a bare function call in FROM, so newer SQLQuack parsers refuse
every Snowflake model that references another.

A shared helper in sqlbuild-analysis (relation_markers::markers_as_names) now
writes each marker call in code as a short indexed name, padded so all later
text keeps its line and column, and returns the calls by index. sql_tree reads
SQL through it for every dialect. The rules crate's dialect lexical syntax moves
to sqlbuild-sqltext so both use one mapping.

kvlonge commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing: every commit on this branch is already contained in #1374 (the combined parser train), which will land this change. The branch is kept; reopen if #1374 is dropped.

@kvlonge kvlonge closed this Nov 8, 2026
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