diff options
Diffstat (limited to 'sqlglot/dialects')
-rw-r--r-- | sqlglot/dialects/bigquery.py | 9 | ||||
-rw-r--r-- | sqlglot/dialects/snowflake.py | 10 |
2 files changed, 12 insertions, 7 deletions
diff --git a/sqlglot/dialects/bigquery.py b/sqlglot/dialects/bigquery.py index 8786063..c9d6c79 100644 --- a/sqlglot/dialects/bigquery.py +++ b/sqlglot/dialects/bigquery.py @@ -96,13 +96,14 @@ def _unqualify_unnest(expression: exp.Expression) -> exp.Expression: These are added by the optimizer's qualify_column step. """ + from sqlglot.optimizer.scope import Scope + if isinstance(expression, exp.Select): for unnest in expression.find_all(exp.Unnest): if isinstance(unnest.parent, (exp.From, exp.Join)) and unnest.alias: - for select in expression.selects: - for column in select.find_all(exp.Column): - if column.table == unnest.alias: - column.set("table", None) + for column in Scope(expression).find_all(exp.Column): + if column.table == unnest.alias: + column.set("table", None) return expression diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py index a2dbfd9..34e4dd0 100644 --- a/sqlglot/dialects/snowflake.py +++ b/sqlglot/dialects/snowflake.py @@ -86,6 +86,10 @@ def _parse_object_construct(args: t.List) -> t.Union[exp.StarMap, exp.Struct]: ) +def _parse_datediff(args: t.List) -> exp.DateDiff: + return exp.DateDiff(this=seq_get(args, 2), expression=seq_get(args, 1), unit=seq_get(args, 0)) + + def _unix_to_time_sql(self: generator.Generator, expression: exp.UnixToTime) -> str: scale = expression.args.get("scale") timestamp = self.sql(expression, "this") @@ -214,15 +218,15 @@ class Snowflake(Dialect): "DATEADD": lambda args: exp.DateAdd( this=seq_get(args, 2), expression=seq_get(args, 1), unit=seq_get(args, 0) ), - "DATEDIFF": lambda args: exp.DateDiff( - this=seq_get(args, 2), expression=seq_get(args, 1), unit=seq_get(args, 0) - ), + "DATEDIFF": _parse_datediff, "DIV0": _div0_to_if, "IFF": exp.If.from_arg_list, "NULLIFZERO": _nullifzero_to_if, "OBJECT_CONSTRUCT": _parse_object_construct, "RLIKE": exp.RegexpLike.from_arg_list, "SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)), + "TIMEDIFF": _parse_datediff, + "TIMESTAMPDIFF": _parse_datediff, "TO_ARRAY": exp.Array.from_arg_list, "TO_VARCHAR": exp.ToChar.from_arg_list, "TO_TIMESTAMP": _snowflake_to_timestamp, |