Skip to content

feat(contracts): prove dynamic pivots from SQLQuack parse trees - #1360

Closed
kvlonge wants to merge 7 commits into
chore/sqlquack-parser-trainfrom
feat/pivot-sqlquack
Closed

kvlonge wants to merge 7 commits into
chore/sqlquack-parser-trainfrom
feat/pivot-sqlquack

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Why

The dynamic column contract proof (K011) still parsed pivot SQL with Polyglot through the analysis session's dict helpers. SQLBuild is moving every parse onto SQLQuack.

Changes

  • The pivot proof parses with SQLQuack's shared parser: DuckDB grammar for DuckDB and MotherDuck, Snowflake grammar for Snowflake. It still requires one statement and walks the same tagged JSON tree.
  • SQLQuack keeps a Snowflake aggregate such as SUM(amount) as a named call with an argument list, where Polyglot used a dedicated node. The proof reads the call's single argument as the aggregated value.
  • Other dialects keep the existing "does not support compiler-proven dynamic pivots" message.
  • Stacked on feat: parse rule facts, types and syntax trees with SQLQuack #1374, whose SQLQuack pin refuses a bare __ref("…") in a Snowflake FROM. The proof now parses through the shared relation-marker helper and reads __ref/__source/__seed back as their relations. Other markers resolve to no relation.
  • The statement depth guard is shared with rule facts instead of copied.
  • The other Polyglot parse helpers stay for the analysis session, which moves with the analysis route.

Verification

  • For the DuckDB pivot shapes in the proof tests (bare pivot, cast aggregate, CTE input, pivot in a subquery), the SQLQuack tree serialises to JSON identical to Polyglot's. Snowflake differs only in the aggregate node described above.
  • Rust analysis-session tests pass, plus a new Snowflake cast-aggregate case. With the argument fallback removed, the existing Snowflake pivot case fails.
  • New Snowflake __ref and DuckDB __dbt_ref passthrough cases. Without the marker step two Snowflake cases fail on feat: parse rule facts, types and syntax trees with SQLQuack #1374's pin.
  • Parse errors keep their text: PIVOT FROM WHERE still reports "Unexpected token: From".
  • E2E dynamic column contract builds and the analysis-session integration tests pass; clippy and fensu pass.

DuckShop: not applicable. DuckDB trees are unchanged, so no new DuckDB shape exists to add, and DuckShop cannot run Snowflake pivots.

The dynamic column contract proof parses pivot SQL with SQLQuack's shared
parser (DuckDB, MotherDuck, Snowflake) instead of Polyglot. DuckDB trees
match Polyglot's exactly; a Snowflake aggregate keeps its argument in a
call's argument list, which the proof now reads. Other dialects keep the
existing unsupported-dialect message.
@kvlonge
kvlonge enabled auto-merge (squash) November 8, 2026 02:10
@kvlonge
kvlonge disabled auto-merge November 8, 2026 12:36
…roofs

Newer SQLQuack Snowflake parsers refuse a bare __ref(...) or __source(...)
in FROM, so the proof parses the model SQL through the shared
markers_as_names helper and renames each dependency marker's table or column
node back to the relation its call names.
…ofs and rule facts

Both crates carried the same iterative deeper_than; sql_tree now owns it.
The deep pivot test asserts its expected outcome directly.
A __dbt_ref passthrough named its internal placeholder in the failure
reason; it now fails as before. The marker scan reads comments and strings
with the dialect the proof parses, so MotherDuck scans as DuckDB.
@kvlonge
kvlonge changed the base branch from main to chore/sqlquack-parser-train November 8, 2026 13:18

kvlonge commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Folded into the single combined sqlbuild PR (D625/D626), which the SQLBuild lane is assembling now and opens once #1377 lands. Branch kept.

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