Skip to content

fix: lay out Snowflake expression macro bodies instead of dedenting them - #1494

Merged
kvlonge merged 1 commit into
mainfrom
fix/snowflake-expression-macro-format
Nov 15, 2026
Merged

kvlonge merged 1 commit into
mainfrom
fix/snowflake-expression-macro-format

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Why

On Snowflake, sqb format didn't lay out an expression-macro body. Each run removed one indentation level until the body was flush left, so sqb format --check never settled. The same body formats properly and stays stable on DuckDB. Scalar SQL function bodies take the same path.

SQLBuild formats an expression body as a one-item SELECT and dedents the result. The Snowflake formatter keeps unaliased select items exactly as written, because Snowflake names such a column by its text. So only the first line moved, and the dedent then stripped one authored level from every other line.

Changes

  • Expression bodies are formatted as an aliased item (alias printed at width 0), so every dialect lays them out. The alias is removed again; a formatted result without it at the end is a fault and the file is left unchanged. A trailing ; stays out of the formatted SQL.
  • The dedent now leaves lines inside a $$ dollar-quoted string alone. Before, it changed the contents of a multi-line $$ string, on every dialect.
  • DuckShop edge case: a scoped Snowflake expression macro whose body holds a comment, used by stg_edge_ticket_notes. Compiled results are unchanged.

Verification

  • New Rust test: the reported macro and a 15-level nested macro, authored flush left, format on DuckDB and Snowflake to the expected layout, and a second run changes nothing. It fails without the fix.
  • New CLI test: project and scoped Snowflake macros format to the expected layout, --check passes, a second run changes nothing, and the project compiles. Fails on the released extension.
  • Formatting all of DuckShop with the fix and with the latest release differs only in its six Snowflake expression-macro files. No faults.
  • cargo test -p sqlbuild-rules, the format-preservation tests, fensu check and clippy pass.

On Snowflake, `sqb format` removed one indentation level from an
expression macro or scalar function body on every run, so `--check` never
settled. The body was formatted as an unaliased SELECT item, which the
Snowflake formatter keeps exactly as written, and the dedent that removes
the SELECT again then stripped an authored level from every line.

Expression bodies are now formatted as an aliased item, which every
dialect lays out, and the alias is removed again; a result without it is
a fault that leaves the file unchanged. The dedent also leaves lines
inside a $$ dollar-quoted string alone instead of changing the string.

DuckShop gains a scoped Snowflake expression macro whose body holds a
comment.
@kvlonge
kvlonge enabled auto-merge November 15, 2026 09:06
@kvlonge
kvlonge added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 1e9f04c Nov 15, 2026
32 checks passed
@kvlonge
kvlonge deleted the fix/snowflake-expression-macro-format branch November 15, 2026 10:01
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