Skip to content

Commit 364afd3

Browse files
pkitgeorgesittas
andauthored
clickhouse: fix parsing of Null engine (#5042)
* Fix: preserve non-participating joins in eliminate_join_marks rule fixes #5039 * clickhouse: fix parsing of Null engine Fixes #5041 --------- Co-authored-by: George Sittas <[email protected]>
1 parent 7c55c48 commit 364afd3

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

sqlglot/dialects/clickhouse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,9 @@ class Parser(parser.Parser):
500500

501501
PROPERTY_PARSERS = parser.Parser.PROPERTY_PARSERS.copy()
502502
PROPERTY_PARSERS.pop("DYNAMIC")
503+
PROPERTY_PARSERS["ENGINE"] = lambda self: self._parse_property_assignment(
504+
exp.EngineProperty, anonymous_func=True
505+
)
503506

504507
NO_PAREN_FUNCTION_PARSERS = parser.Parser.NO_PAREN_FUNCTION_PARSERS.copy()
505508
NO_PAREN_FUNCTION_PARSERS.pop("ANY")

sqlglot/parser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,18 +2196,22 @@ def _parse_stored(self) -> t.Union[exp.FileFormatProperty, exp.StorageHandlerPro
21962196
),
21972197
)
21982198

2199-
def _parse_unquoted_field(self) -> t.Optional[exp.Expression]:
2200-
field = self._parse_field()
2199+
def _parse_unquoted_field(self, anonymous_func: bool = False) -> t.Optional[exp.Expression]:
2200+
field = self._parse_field(anonymous_func=anonymous_func)
22012201
if isinstance(field, exp.Identifier) and not field.quoted:
22022202
field = exp.var(field)
22032203

22042204
return field
22052205

2206-
def _parse_property_assignment(self, exp_class: t.Type[E], **kwargs: t.Any) -> E:
2206+
def _parse_property_assignment(
2207+
self, exp_class: t.Type[E], anonymous_func: bool = False, **kwargs: t.Any
2208+
) -> E:
22072209
self._match(TokenType.EQ)
22082210
self._match(TokenType.ALIAS)
22092211

2210-
return self.expression(exp_class, this=self._parse_unquoted_field(), **kwargs)
2212+
return self.expression(
2213+
exp_class, this=self._parse_unquoted_field(anonymous_func=anonymous_func), **kwargs
2214+
)
22112215

22122216
def _parse_properties(self, before: t.Optional[bool] = None) -> t.Optional[exp.Properties]:
22132217
properties = []

tests/dialects/test_clickhouse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def test_clickhouse(self):
167167
self.validate_identity(
168168
"CREATE MATERIALIZED VIEW test_view ON CLUSTER '{cluster}' (id UInt8) ENGINE=AggregatingMergeTree() ORDER BY tuple() AS SELECT * FROM test_data"
169169
)
170+
self.validate_identity("CREATE TABLE test (id UInt8) ENGINE=Null()")
170171
self.validate_identity(
171172
"CREATE MATERIALIZED VIEW test_view ON CLUSTER cl1 TO table1 AS SELECT * FROM test_data"
172173
)

0 commit comments

Comments
 (0)