diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-08-14 10:12:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-08-14 10:12:13 +0000 |
commit | cdffd0b29d5b072639bb02118d6828f4d1b76099 (patch) | |
tree | 57ec0b75c40e40a33060b63599bbba6f0af27ae8 /sqlglot/dialects/dialect.py | |
parent | Adding upstream version 17.11.0. (diff) | |
download | sqlglot-cdffd0b29d5b072639bb02118d6828f4d1b76099.tar.xz sqlglot-cdffd0b29d5b072639bb02118d6828f4d1b76099.zip |
Adding upstream version 17.12.0.upstream/17.12.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 | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/sqlglot/dialects/dialect.py b/sqlglot/dialects/dialect.py index 1d0584c..132496f 100644 --- a/sqlglot/dialects/dialect.py +++ b/sqlglot/dialects/dialect.py @@ -39,6 +39,7 @@ class Dialects(str, Enum): TERADATA = "teradata" TRINO = "trino" TSQL = "tsql" + Doris = "doris" class _Dialect(type): @@ -121,7 +122,7 @@ class _Dialect(type): if hasattr(subclass, name): setattr(subclass, name, value) - if not klass.STRICT_STRING_CONCAT: + if not klass.STRICT_STRING_CONCAT and klass.DPIPE_IS_STRING_CONCAT: klass.parser_class.BITWISE[TokenType.DPIPE] = exp.SafeDPipe klass.generator_class.can_identify = klass.can_identify @@ -146,6 +147,9 @@ class Dialect(metaclass=_Dialect): # Determines whether or not an unquoted identifier can start with a digit IDENTIFIERS_CAN_START_WITH_DIGIT = False + # Determines whether or not the DPIPE token ('||') is a string concatenation operator + DPIPE_IS_STRING_CONCAT = True + # Determines whether or not CONCAT's arguments must be strings STRICT_STRING_CONCAT = False @@ -460,6 +464,20 @@ def format_time_lambda( return _format_time +def time_format( + dialect: DialectType = None, +) -> t.Callable[[Generator, exp.UnixToStr | exp.StrToUnix], t.Optional[str]]: + def _time_format(self: Generator, expression: exp.UnixToStr | exp.StrToUnix) -> t.Optional[str]: + """ + Returns the time format for a given expression, unless it's equivalent + to the default time format of the dialect of interest. + """ + time_format = self.format_time(expression) + return time_format if time_format != Dialect.get_or_raise(dialect).TIME_FORMAT else None + + return _time_format + + def create_with_partitions_sql(self: Generator, expression: exp.Create) -> str: """ In Hive and Spark, the PARTITIONED BY property acts as an extension of a table's schema. When the @@ -699,3 +717,8 @@ def simplify_literal(expression: E) -> E: def binary_from_function(expr_type: t.Type[B]) -> t.Callable[[t.List], B]: return lambda args: expr_type(this=seq_get(args, 0), expression=seq_get(args, 1)) + + +# Used to represent DATE_TRUNC in Doris, Postgres and Starrocks dialects +def parse_timestamp_trunc(args: t.List) -> exp.TimestampTrunc: + return exp.TimestampTrunc(this=seq_get(args, 1), unit=seq_get(args, 0)) |