Skip to content

Commit

Permalink
Fix(clickhouse): improve struct type parsing (#3547)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored May 24, 2024
1 parent 57faa3e commit 1a8a16b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4274,7 +4274,7 @@ def _parse_types(

if self._match(TokenType.L_PAREN):
if is_struct:
expressions = self._parse_csv(self._parse_struct_types)
expressions = self._parse_csv(lambda: self._parse_struct_types(type_required=True))
elif nested:
expressions = self._parse_csv(
lambda: self._parse_types(
Expand Down Expand Up @@ -4392,15 +4392,16 @@ def _parse_struct_types(self, type_required: bool = False) -> t.Optional[exp.Exp
or self._parse_id_var()
)
self._match(TokenType.COLON)
column_def = self._parse_column_def(this)

if type_required and (
(isinstance(this, exp.Column) and this.this is column_def) or this is column_def
if (
type_required
and not isinstance(this, exp.DataType)
and not self._match_set(self.TYPE_TOKENS, advance=False)
):
self._retreat(index)
return self._parse_types()

return column_def
return self._parse_column_def(this)

def _parse_at_time_zone(self, this: t.Optional[exp.Expression]) -> t.Optional[exp.Expression]:
if not self._match_text_seq("AT", "TIME", "ZONE"):
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_clickhouse(self):
self.assertEqual(expr.sql(dialect="clickhouse"), "COUNT(x)")
self.assertIsNone(expr._meta)

self.validate_identity("SELECT CAST(x AS Tuple(String, Array(Nullable(Float64))))")
self.validate_identity("countIf(x, y)")
self.validate_identity("x = y")
self.validate_identity("x <> y")
Expand Down

0 comments on commit 1a8a16b

Please sign in to comment.