Repository navigation
fix(dialect): don't parse @@ system variables as macros - #6117
manan28025 wants to merge 1 commit into
Conversation
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>
|
Sorry for the slow review. I checked that the new tests fail on main and pass here. This also stops One change before we merge. The new branch fires whenever the next token is def _at_system_variable(self: Parser) -> bool:
at, name = self._curr, self._next
if not at or not name or at.text != SQLMESH_MACRO_PREFIX or name.token_type != TokenType.VAR:
return False
if at.start != self._prev.end + 1 or name.start != at.end + 1:
return False
after = seq_get(self._tokens, self._index + 2)
return not after or after.token_type != TokenType.L_PARENWith that, every macro form I tried parses the same as on main, and your tests still pass. Could you add cases for |
Description
Fixes #5601.
In
_parse_macro, the second@of@@DATEFIRSTwas parsed as the start of a macro variable, so system variables like T-SQL's@@DATEFIRST/@@ROWCOUNTand BigQuery's@@query_labelbecame aMacroVar. The model then failed to render withUnsupported expression type MacroVar.@@namecan'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
test_double_at_system_variable_is_not_a_macro(tsql, bigquery, mysql) andtest_double_at_system_variable_in_model, which renders a T-SQL model using@@DATEFIRSTnext to a regular@xmacro. The tsql, bigquery and model tests fail on main. MySQL already worked, since it tokenizes@@session...differently.Checklist
make styleand fixed any issuesmake fast-test) (ran the tests/core fast and slow suites, see above)git commit -s) per the DCO