Skip to content

Commit

Permalink
fix(clickhouse): unparseable AggregateFunction(count) (#4812)
Browse files Browse the repository at this point in the history
count is the only agg function that may not have argument at all
  • Loading branch information
pkit authored Feb 27, 2025
1 parent e34f3bc commit 5ef35f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 11 additions & 6 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5048,14 +5048,19 @@ def _parse_types(
func_or_ident = self._parse_function(anonymous=True) or self._parse_id_var(
any_token=False, tokens=(TokenType.VAR, TokenType.ANY)
)
if not func_or_ident or not self._match(TokenType.COMMA):
if not func_or_ident:
return None
expressions = self._parse_csv(
lambda: self._parse_types(
check_func=check_func, schema=schema, allow_identifiers=allow_identifiers
expressions = [func_or_ident]
if self._match(TokenType.COMMA):
expressions.extend(
self._parse_csv(
lambda: self._parse_types(
check_func=check_func,
schema=schema,
allow_identifiers=allow_identifiers,
)
)
)
)
expressions.insert(0, func_or_ident)
else:
expressions = self._parse_csv(self._parse_type_size)

Expand Down
6 changes: 4 additions & 2 deletions tests/dialects/test_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,13 +1116,15 @@ def test_ddl(self):
CREATE TABLE t (
a AggregateFunction(quantiles(0.5, 0.9), UInt64),
b AggregateFunction(quantiles, UInt64),
c SimpleAggregateFunction(sum, Float64)
c SimpleAggregateFunction(sum, Float64),
d AggregateFunction(count)
)""",
write={
"clickhouse": """CREATE TABLE t (
a AggregateFunction(quantiles(0.5, 0.9), UInt64),
b AggregateFunction(quantiles, UInt64),
c SimpleAggregateFunction(sum, Float64)
c SimpleAggregateFunction(sum, Float64),
d AggregateFunction(count)
)"""
},
pretty=True,
Expand Down

0 comments on commit 5ef35f2

Please sign in to comment.