diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-09-25 08:20:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-09-25 08:20:09 +0000 |
commit | 4554ab4c7d6b2bbbaa6f4d0b810bf477d1a505a6 (patch) | |
tree | 8f4f60a82ab9cd6dcd41397e4ecb2960c332b209 /sqlglot/dialects/dialect.py | |
parent | Releasing debian version 18.5.1-1. (diff) | |
download | sqlglot-4554ab4c7d6b2bbbaa6f4d0b810bf477d1a505a6.tar.xz sqlglot-4554ab4c7d6b2bbbaa6f4d0b810bf477d1a505a6.zip |
Merging upstream version 18.7.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/dialect.py')
-rw-r--r-- | sqlglot/dialects/dialect.py | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/sqlglot/dialects/dialect.py b/sqlglot/dialects/dialect.py index d4811c5..ccf04da 100644 --- a/sqlglot/dialects/dialect.py +++ b/sqlglot/dialects/dialect.py @@ -125,6 +125,12 @@ class _Dialect(type): if not klass.STRICT_STRING_CONCAT and klass.DPIPE_IS_STRING_CONCAT: klass.parser_class.BITWISE[TokenType.DPIPE] = exp.SafeDPipe + if not klass.SUPPORTS_SEMI_ANTI_JOIN: + klass.parser_class.TABLE_ALIAS_TOKENS = klass.parser_class.TABLE_ALIAS_TOKENS | { + TokenType.ANTI, + TokenType.SEMI, + } + klass.generator_class.can_identify = klass.can_identify return klass @@ -156,9 +162,15 @@ class Dialect(metaclass=_Dialect): # Determines whether or not user-defined data types are supported SUPPORTS_USER_DEFINED_TYPES = True + # Determines whether or not SEMI/ANTI JOINs are supported + SUPPORTS_SEMI_ANTI_JOIN = True + # Determines how function names are going to be normalized NORMALIZE_FUNCTIONS: bool | str = "upper" + # Determines whether the base comes first in the LOG function + LOG_BASE_FIRST = True + # Indicates the default null ordering method to use if not explicitly set # Options are: "nulls_are_small", "nulls_are_large", "nulls_are_last" NULL_ORDERING = "nulls_are_small" @@ -331,10 +343,18 @@ def approx_count_distinct_sql(self: Generator, expression: exp.ApproxDistinct) - return self.func("APPROX_COUNT_DISTINCT", expression.this) -def if_sql(self: Generator, expression: exp.If) -> str: - return self.func( - "IF", expression.this, expression.args.get("true"), expression.args.get("false") - ) +def if_sql( + name: str = "IF", false_value: t.Optional[exp.Expression | str] = None +) -> t.Callable[[Generator, exp.If], str]: + def _if_sql(self: Generator, expression: exp.If) -> str: + return self.func( + name, + expression.this, + expression.args.get("true"), + expression.args.get("false") or false_value, + ) + + return _if_sql def arrow_json_extract_sql(self: Generator, expression: exp.JSONExtract | exp.JSONBExtract) -> str: @@ -751,6 +771,12 @@ def any_value_to_max_sql(self: Generator, expression: exp.AnyValue) -> str: return self.func("MAX", expression.this) +def bool_xor_sql(self: Generator, expression: exp.Xor) -> str: + a = self.sql(expression.left) + b = self.sql(expression.right) + return f"({a} AND (NOT {b})) OR ((NOT {a}) AND {b})" + + # Used to generate JSON_OBJECT with a comma in BigQuery and MySQL instead of colon def json_keyvalue_comma_sql(self: Generator, expression: exp.JSONKeyValue) -> str: return f"{self.sql(expression, 'this')}, {self.sql(expression, 'expression')}" @@ -764,3 +790,10 @@ def is_parse_json(expression: exp.Expression) -> bool: def isnull_to_is_null(args: t.List) -> exp.Expression: return exp.Paren(this=exp.Is(this=seq_get(args, 0), expression=exp.null())) + + +def move_insert_cte_sql(self: Generator, expression: exp.Insert) -> str: + if expression.expression.args.get("with"): + expression = expression.copy() + expression.set("with", expression.expression.args["with"].pop()) + return self.insert_sql(expression) |