Skip to content

Parse @name as a parameter in the Trino dialect - #14

Closed
ravenac95 wants to merge 2 commits into
mainfrom
oso-6400-trino-at-parameter
Closed

ravenac95 wants to merge 2 commits into
mainfrom
oso-6400-trino-at-parameter

Conversation

@ravenac95

Copy link
Copy Markdown
Member

What

In the Trino dialect, @name now tokenizes as DAt + name, so the parser builds Expression::Parameter { style: ParameterStyle::At, name: Some("name") }, with the name's case preserved. The generator writes it back as @name.

@name( (a sqlmesh macro function call such as @each(...)) is unchanged: it stays a Var identifier and still round-trips as @NAME(...).

Why

Today every dialect turns @word into a TSQL-style @variable identifier, so in Trino a sqlmesh macro variable like @start_dt parses as a column. Column extraction on multi-table queries then fails with an ambiguous column reference, and lineage reports the macro as unresolved. kuma's query rewriter is about to substitute these macros with a run's time range, which needs them as parameter nodes.

How

  • New TokenizerConfig::at_sign_is_parameter (default false). Only TrinoDialect sets it, so every other dialect (TSQL variables, Snowflake @stage, …) tokenizes exactly as before. Note that DuneDialect reuses Trino's tokenizer config, so Dune gets the same behaviour.
  • at_word_is_call looks ahead over the word, using the same character set the TSQL identifier scanner consumes, to keep @name( on the old path. Whitespace before ( is not treated as a call (marked ponytail:).
  • Side effect: in Trino, FROM @name now goes through the existing stage-reference path instead of producing a table named @name.

Tests

  • dialects::trino::tests: SELECT @start_dt FROM t parses to an At parameter named start_dt and round-trips. @some_macro_func('x') still round-trips.
  • cargo test -p polyglot-sql --lib passes (1345 tests). cargo fmt --all --check is clean.
  • In a full local cargo test, custom_clickhouse_parser failed (missing fixture directory) and so did tpch_transpile_stack (a debug-build stack/hang). Neither involves Trino or @, and CI provides those fixtures.

Consumed by opensource-observer/kuma (OSO-6400), which will re-pin polyglot-sql to this PR's merge commit.

🤖 Generated with Claude Code

https://claude.ai/code/session_019snAi4ViWsw4dALcjcASho


Generated by Claude Code

sqlmesh macro variables such as @start_dt tokenized as TSQL-style identifiers
and parsed as columns. Trino now emits DAt for @name (not @name( calls), so the
parser builds Parameter { style: At }.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019snAi4ViWsw4dALcjcASho
…tion

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019snAi4ViWsw4dALcjcASho
@linear-code

linear-code Bot commented Oct 13, 2026

Copy link
Copy Markdown

OSO-6400

Copy link
Copy Markdown
Member Author

Closing this without merging. sqlmesh macro parsing doesn't belong in the polyglot fork, so kuma's query rewriter will normalize Trino @name columns into Parameter { style: At } nodes itself, right after parsing (opensource-observer/kuma#10118). The fork stays at its current rev.


Generated by Claude Code

@ravenac95 ravenac95 closed this Oct 13, 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.

2 participants