Skip to content

Commit 1b3ea34

Browse files
committed
Refactor(clickhouse): override _parse_property_assignment to handle null engine
1 parent 364afd3 commit 1b3ea34

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

sqlglot/dialects/clickhouse.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
from sqlglot.tokens import Token, TokenType
2828
from sqlglot.generator import unsupported_args
2929

30+
if t.TYPE_CHECKING:
31+
from sqlglot._typing import E
32+
3033
DATEΤΙΜΕ_DELTA = t.Union[exp.DateAdd, exp.DateDiff, exp.DateSub, exp.TimestampSub, exp.TimestampAdd]
3134

3235

@@ -500,9 +503,6 @@ class Parser(parser.Parser):
500503

501504
PROPERTY_PARSERS = parser.Parser.PROPERTY_PARSERS.copy()
502505
PROPERTY_PARSERS.pop("DYNAMIC")
503-
PROPERTY_PARSERS["ENGINE"] = lambda self: self._parse_property_assignment(
504-
exp.EngineProperty, anonymous_func=True
505-
)
506506

507507
NO_PAREN_FUNCTION_PARSERS = parser.Parser.NO_PAREN_FUNCTION_PARSERS.copy()
508508
NO_PAREN_FUNCTION_PARSERS.pop("ANY")
@@ -571,6 +571,12 @@ class Parser(parser.Parser):
571571
TokenType.L_BRACE: lambda self: self._parse_query_parameter(),
572572
}
573573

574+
def _parse_property_assignment(self, exp_class: t.Type[E], **kwargs: t.Any) -> E:
575+
this = super()._parse_property_assignment(exp_class, **kwargs)
576+
if isinstance(this, exp.EngineProperty) and isinstance(this.this, exp.Null):
577+
this.this.replace(exp.Anonymous(this="Null"))
578+
return this
579+
574580
# https://clickhouse.com/docs/en/sql-reference/statements/create/function
575581
def _parse_user_defined_function_expression(self) -> t.Optional[exp.Expression]:
576582
return self._parse_lambda()

sqlglot/parser.py

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

2199-
def _parse_unquoted_field(self, anonymous_func: bool = False) -> t.Optional[exp.Expression]:
2200-
field = self._parse_field(anonymous_func=anonymous_func)
2199+
def _parse_unquoted_field(self) -> t.Optional[exp.Expression]:
2200+
field = self._parse_field()
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(
2207-
self, exp_class: t.Type[E], anonymous_func: bool = False, **kwargs: t.Any
2208-
) -> E:
2206+
def _parse_property_assignment(self, exp_class: t.Type[E], **kwargs: t.Any) -> E:
22092207
self._match(TokenType.EQ)
22102208
self._match(TokenType.ALIAS)
22112209

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

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

0 commit comments

Comments
 (0)