Skip to content

fix: read Databricks and DuckDB strings with their own escape rules - #1502

Queued
kvlonge wants to merge 1 commit into
mainfrom
fix/backslash-escape-dialects
Queued

kvlonge wants to merge 1 commit into
mainfrom
fix/backslash-escape-dialects

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Why

sqb format re-indents expression macro bodies using SQLBuild's lexical rules for the project's dialect. Databricks and DuckDB shared one entry with no backslash escapes, no raw strings and flat block comments. SQLQuack and both adapters read them differently: Databricks honours \' in '...' and "..." outside r'...', DuckDB honours it inside E'...', and both nest block comments. A multi-line string after \' therefore looked closed early, and its next line lost two spaces on every run, changing the value (6 → 4 → 2 → 0 spaces) so sqb format --check never settled.

Changes

  • Databricks gets its own entry: backslash escapes in ' and ", the r'...' raw prefix and nested block comments.
  • DuckDB falls through to the default PostgreSQL entry (E'...' escapes, nested block comments), as its adapter already declares.
  • The same rules decide quoted text for semantic-validation normalisation, fast lineage, dynamic pivot, SQL tree nodes and query-facts shapes; markers after such strings or nested comments are now found where they were skipped.
  • Tests: scanner cases for both dialects, including raw strings, a plain DuckDB string and nested comments; format-twice cases on Databricks, DuckDB E'' and a nested comment holding an apostrophe; the CLI format test now covers Databricks and DuckDB projects.
  • DuckShop is a Snowflake project and cannot express a Databricks- or DuckDB-only lexical case; its Snowflake backslash case already exists.

Verification

  • The new scanner, format and CLI cases fail before the fix and pass after it.
  • sqb format three times on the repro macro: before, kept indent loses two spaces per run on both dialects; after, it keeps all six on every run.
  • cargo test -p sqlbuild-sqltext -p sqlbuild-rules -p sqlbuild-analysis --lib, make test and make check-ci pass.

SQLBuild's lexical rules gave Databricks and DuckDB one shared entry
with no backslash escapes, no raw strings and flat block comments.
SQLQuack and both adapters read them differently: Databricks honours a
backslash in '...' and "..." outside r'...' raw strings, DuckDB honours
it inside E'...', and both nest block comments.

The expression-macro dedent in sqb format reads the formatted body with
these rules. A multi-line string after a backslash-escaped quote looked
closed early, so its next line lost two spaces on every run and the
string's value changed.

Databricks now has its own entry, and DuckDB uses the PostgreSQL rules
its adapter already declares. The same rules decide quoted text for
semantic-validation normalisation, fast lineage, dynamic pivot, SQL
tree nodes and query-facts shapes.
@kvlonge
kvlonge enabled auto-merge November 15, 2026 15:44
@kvlonge
kvlonge added this pull request to the merge queue Nov 15, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 15, 2026
@kvlonge
kvlonge added this pull request to the merge queue Nov 15, 2026
Any commits made after this event will not be merged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant