Skip to content

fix(compiler): treat dollar-quoted strings as quoted text in variable substitution - #1020

Merged
kvlonge merged 2 commits into
mainfrom
fix/dollar-quote-vars
Oct 8, 2026
Merged

kvlonge merged 2 commits into
mainfrom
fix/dollar-quote-vars

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Why

The native @@var fast path that prepares every model's SQL on all engines did not treat $$...$$ or $tag$...$tag$ as quoted text, unlike the pure-Python scanner. SELECT $$--@@region$$ kept @@region (Python: $$--north$$), and an unclosed $tag$ failed later with "Enum and constant expansion" or "SQL reference" errors instead of "SQL interpolation contains an unclosed quoted string". The harness missed it because its python oracle shares the native path.

Changes

  • The native substitution scanner now uses the shared compiler scanner (non_code_end, compiler quote policy), which reads dollar quotes exactly like Python (tag grammar, $1 and a$b are code). Unclosed quotes fall back to Python, which raises the interpolation error. Tokens inside quoted segments are substituted as in Python.
  • The native enum/constant and reference scanners already handled dollar quotes.
  • The preview ATTACHMENTS path no longer hands $ SQL to Python; the guard and the unused SQL_DOLLAR_QUOTE_TOKEN constant are removed.
  • Tests: Rust cases; a native-vs-pure-Python differential on 4,000 generated strings; an expand_authored_sql_result parity case (python vs native-preview) on dollar-heavy strings with variables, enum/constant references and unclosed quotes; dollar-quoted SQL in the attachment project's source, unit test and audit; an E2E sqb compile DuckDB test on each engine; a harness generator line and failure-corpus case.

Verification

  • cargo test --workspace --all-features, clippy, fmt (Rust 1.98.0)
  • Focused pytest for the new tests
  • make compiler-differential, make compiler-differential-shipped, tests/e2e/scripts/compiler_differential
  • make check-ci, make test

… substitution

The native @@var fast path on the model path now scans with the shared
compiler scanner, so dollar-quoted text is quoted exactly as in the
pure-Python scanner and an unclosed dollar quote falls back to Python's
interpolation error. Adds a native-versus-Python differential test, Rust
cases, an E2E compile test on each engine, and harness cases.
…tachments path

The native substitution scanner now reads dollar quotes like Python, so
the preview ATTACHMENTS stage no longer hands SQL containing $ to the
Python scanner. Adds dollar-heavy authored SQL parity and dollar-quoted
attachment project SQL.
@kvlonge
kvlonge force-pushed the fix/dollar-quote-vars branch from 1a7a60b to 981b0ed Compare October 8, 2026 04:20
@kvlonge
kvlonge merged commit c9b0985 into main Oct 8, 2026
38 checks passed
@kvlonge
kvlonge deleted the fix/dollar-quote-vars branch October 8, 2026 05:03
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