diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 08:11:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 08:12:02 +0000 |
commit | 8d36f5966675e23bee7026ba37ae0647fbf47300 (patch) | |
tree | df4227bbb3b07cb70df87237bcff03c8efd7822d /sqlglot/dialects/drill.py | |
parent | Releasing debian version 22.2.0-1. (diff) | |
download | sqlglot-8d36f5966675e23bee7026ba37ae0647fbf47300.tar.xz sqlglot-8d36f5966675e23bee7026ba37ae0647fbf47300.zip |
Merging upstream version 23.7.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/drill.py')
-rw-r--r-- | sqlglot/dialects/drill.py | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/sqlglot/dialects/drill.py b/sqlglot/dialects/drill.py index c1f6afa..0a00d92 100644 --- a/sqlglot/dialects/drill.py +++ b/sqlglot/dialects/drill.py @@ -1,6 +1,5 @@ from __future__ import annotations -import typing as t from sqlglot import exp, generator, parser, tokens, transforms from sqlglot.dialects.dialect import ( @@ -12,18 +11,10 @@ from sqlglot.dialects.dialect import ( str_position_sql, timestrtotime_sql, ) +from sqlglot.dialects.mysql import date_add_sql from sqlglot.transforms import preprocess, move_schema_columns_to_partitioned_by -def _date_add_sql(kind: str) -> t.Callable[[Drill.Generator, exp.DateAdd | exp.DateSub], str]: - def func(self: Drill.Generator, expression: exp.DateAdd | exp.DateSub) -> str: - this = self.sql(expression, "this") - unit = exp.var(expression.text("unit").upper() or "DAY") - return self.func(f"DATE_{kind}", this, exp.Interval(this=expression.expression, unit=unit)) - - return func - - def _str_to_date(self: Drill.Generator, expression: exp.StrToDate) -> str: this = self.sql(expression, "this") time_format = self.format_time(expression) @@ -84,7 +75,6 @@ class Drill(Dialect): FUNCTIONS = { **parser.Parser.FUNCTIONS, - "DATE_FORMAT": build_formatted_time(exp.TimeToStr, "drill"), "TO_TIMESTAMP": exp.TimeStrToTime.from_arg_list, "TO_CHAR": build_formatted_time(exp.TimeToStr, "drill"), } @@ -124,9 +114,9 @@ class Drill(Dialect): exp.ArrayContains: rename_func("REPEATED_CONTAINS"), exp.ArraySize: rename_func("REPEATED_COUNT"), exp.Create: preprocess([move_schema_columns_to_partitioned_by]), - exp.DateAdd: _date_add_sql("ADD"), + exp.DateAdd: date_add_sql("ADD"), exp.DateStrToDate: datestrtodate_sql, - exp.DateSub: _date_add_sql("SUB"), + exp.DateSub: date_add_sql("SUB"), exp.DateToDi: lambda self, e: f"CAST(TO_DATE({self.sql(e, 'this')}, {Drill.DATEINT_FORMAT}) AS INT)", exp.DiToDate: lambda self, |