You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Conditions in the Built-in Audits dont support macro vars #2399
However, if you want to use @start_dt and @end_dt in the condition to limit the amount of data scanned on the underlying engine, they dont expand out correctly.
For example, this condition fails:
condition=ts between @start_dt and @end_dt
-- ValueError: Unsupported expression type MacroVar
You can wrap it in @SQL to get further:
condition=@SQL('ts between @start_dt and @end_dt')
-- sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 1, Col: 38.
ts between 2023-03-01 00:00:00+00:00 and 2023-03-10 23:59:59.999999+00:00
Error: Failed to resolve macro for expression. Error trying to eval macro.
Generated code: self.parse_one(self.template('ts between @start_dt and @end_dt', locals()))
Original sql: @SQL('ts between @start_dt and @end_dt') at '.'
It seems that it doesn't take the current dialect into account and just does a string substitution. That same expression in a normal model would correctly expand to CAST('@start_dt' AS TIMESTAMP) AND CAST('@end_dt' AS TIMESTAMP)
You can work around the dialect issue by writing SQL to convert the string values to timestamps:
condition=@SQL('ts between cast(''@start_dt'' as timestamp) and cast(''@end_dt'' as timestamp)')
However, that's a bit hacky. It would be good if the rules for the model SQL dialect were applied
Activity
fix: allow macros to recursively resolve closes SQLMesh#2399 (SQLMesh…