diff options
Diffstat (limited to 'sqlglot/expressions.py')
-rw-r--r-- | sqlglot/expressions.py | 72 |
1 files changed, 59 insertions, 13 deletions
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py index a4c4e95..da4a4ed 100644 --- a/sqlglot/expressions.py +++ b/sqlglot/expressions.py @@ -1653,12 +1653,16 @@ class Join(Expression): "side": False, "kind": False, "using": False, - "natural": False, + "method": False, "global": False, "hint": False, } @property + def method(self) -> str: + return self.text("method").upper() + + @property def kind(self) -> str: return self.text("kind").upper() @@ -1913,6 +1917,24 @@ class LanguageProperty(Property): arg_types = {"this": True} +class DictProperty(Property): + arg_types = {"this": True, "kind": True, "settings": False} + + +class DictSubProperty(Property): + pass + + +class DictRange(Property): + arg_types = {"this": True, "min": True, "max": True} + + +# Clickhouse CREATE ... ON CLUSTER modifier +# https://clickhouse.com/docs/en/sql-reference/distributed-ddl +class OnCluster(Property): + arg_types = {"this": True} + + class LikeProperty(Property): arg_types = {"this": True, "expressions": False} @@ -2797,12 +2819,12 @@ class Select(Subqueryable): Returns: Select: the modified expression. """ - parse_args = {"dialect": dialect, **opts} + parse_args: t.Dict[str, t.Any] = {"dialect": dialect, **opts} try: - expression = maybe_parse(expression, into=Join, prefix="JOIN", **parse_args) # type: ignore + expression = maybe_parse(expression, into=Join, prefix="JOIN", **parse_args) except ParseError: - expression = maybe_parse(expression, into=(Join, Expression), **parse_args) # type: ignore + expression = maybe_parse(expression, into=(Join, Expression), **parse_args) join = expression if isinstance(expression, Join) else Join(this=expression) @@ -2810,14 +2832,14 @@ class Select(Subqueryable): join.this.replace(join.this.subquery()) if join_type: - natural: t.Optional[Token] + method: t.Optional[Token] side: t.Optional[Token] kind: t.Optional[Token] - natural, side, kind = maybe_parse(join_type, into="JOIN_TYPE", **parse_args) # type: ignore + method, side, kind = maybe_parse(join_type, into="JOIN_TYPE", **parse_args) # type: ignore - if natural: - join.set("natural", True) + if method: + join.set("method", method.text) if side: join.set("side", side.text) if kind: @@ -3222,6 +3244,18 @@ class DataType(Expression): DATE = auto() DATETIME = auto() DATETIME64 = auto() + INT4RANGE = auto() + INT4MULTIRANGE = auto() + INT8RANGE = auto() + INT8MULTIRANGE = auto() + NUMRANGE = auto() + NUMMULTIRANGE = auto() + TSRANGE = auto() + TSMULTIRANGE = auto() + TSTZRANGE = auto() + TSTZMULTIRANGE = auto() + DATERANGE = auto() + DATEMULTIRANGE = auto() DECIMAL = auto() DOUBLE = auto() FLOAT = auto() @@ -3331,8 +3365,8 @@ class DataType(Expression): return DataType(**{**data_type_exp.args, **kwargs}) - def is_type(self, dtype: DataType.Type) -> bool: - return self.this == dtype + def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: + return any(self.this == DataType.build(dtype).this for dtype in dtypes) # https://www.postgresql.org/docs/15/datatype-pseudo.html @@ -3846,8 +3880,8 @@ class Cast(Func): def output_name(self) -> str: return self.name - def is_type(self, dtype: DataType.Type) -> bool: - return self.to.is_type(dtype) + def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: + return self.to.is_type(*dtypes) class CastToStrType(Func): @@ -4130,8 +4164,16 @@ class Least(Func): is_var_len_args = True +class Left(Func): + arg_types = {"this": True, "expression": True} + + +class Right(Func): + arg_types = {"this": True, "expression": True} + + class Length(Func): - pass + _sql_names = ["LENGTH", "LEN"] class Levenshtein(Func): @@ -4356,6 +4398,10 @@ class NumberToStr(Func): arg_types = {"this": True, "format": True} +class FromBase(Func): + arg_types = {"this": True, "expression": True} + + class Struct(Func): arg_types = {"expressions": True} is_var_len_args = True |