Skip to content

fix(dialect): don't parse @@ system variables as macros - #6117

Open
manan28025 wants to merge 1 commit into
SQLMesh:mainfrom
manan28025:tsql-double-at-variables
Open

manan28025 wants to merge 1 commit into
SQLMesh:mainfrom
manan28025:tsql-double-at-variables

Conversation

@manan28025

Copy link
Copy Markdown
Contributor

Description

Fixes #5601.

In _parse_macro, the second @ of @@DATEFIRST was parsed as the start of a macro variable, so system variables like T-SQL's @@DATEFIRST / @@ROWCOUNT and BigQuery's @@query_label became a MacroVar. The model then failed to render with Unsupported expression type MacroVar.

@@name can't be a macro reference, so it's now parsed as a system variable (Parameter(Parameter(...))), the same way sqlglot parses it for these dialects. A single @ is still a macro.

Test Plan

  • Added test_double_at_system_variable_is_not_a_macro (tsql, bigquery, mysql) and test_double_at_system_variable_in_model, which renders a T-SQL model using @@DATEFIRST next to a regular @x macro. The tsql, bigquery and model tests fail on main. MySQL already worked, since it tokenizes @@session... differently.
  • Ran the fast and slow tests in tests/core. The only failures are MSSQL/Fabric connection tests that need pyodbc / mssql-python, which I don't have installed. They fail the same way on main.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test) (ran the tests/core fast and slow suites, see above)
  • My commits are signed off (git commit -s) per the DCO

The macro parser treated the second @ in @@DATEFIRST as the start of a
macro variable, so T-SQL configuration functions like @@DATEFIRST and
BigQuery's @@query_label became a MacroVar and the model failed to render
with "Unsupported expression type MacroVar". @@name is now parsed as a
system variable, the same way the dialect parses it.

Signed-off-by: neatninja <manan81140@gmail.com>
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.

don't treat identifiers starting with @@ as macro

2 participants