Skip to content

Commit

Permalink
Fix(snowflake): better support for LISTAGG (#2147)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored Sep 3, 2023
1 parent 5df9b5f commit 7b589ae
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sqlglot/dialects/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class Parser(parser.Parser):
"DATEDIFF": _parse_datediff,
"DIV0": _div0_to_if,
"IFF": exp.If.from_arg_list,
"LISTAGG": exp.GroupConcat.from_arg_list,
"NULLIFZERO": _nullifzero_to_if,
"OBJECT_CONSTRUCT": _parse_object_construct,
"REGEXP_REPLACE": _parse_regexp_replace,
Expand Down Expand Up @@ -361,6 +362,7 @@ class Generator(generator.Generator):
exp.DataType: _datatype_sql,
exp.DayOfWeek: rename_func("DAYOFWEEK"),
exp.Extract: rename_func("DATE_PART"),
exp.GroupConcat: rename_func("LISTAGG"),
exp.If: rename_func("IFF"),
exp.LogicalAnd: rename_func("BOOLAND_AGG"),
exp.LogicalOr: rename_func("BOOLOR_AGG"),
Expand Down
2 changes: 1 addition & 1 deletion sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4449,7 +4449,7 @@ class Greatest(Func):
is_var_len_args = True


class GroupConcat(Func):
class GroupConcat(AggFunc):
arg_types = {"this": True, "separator": False}


Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_snowflake(self):
},
)

self.validate_identity("LISTAGG(data['some_field'], ',')")
self.validate_identity("WEEKOFYEAR(tstamp)")
self.validate_identity("SELECT SUM(amount) FROM mytable GROUP BY ALL")
self.validate_identity("WITH x AS (SELECT 1 AS foo) SELECT foo FROM IDENTIFIER('x')")
Expand Down

0 comments on commit 7b589ae

Please sign in to comment.