1
0
Fork 0

Adding upstream version 7.1.3.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 14:46:14 +01:00
parent 291e0c125c
commit 768d386bf5
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
42 changed files with 1430 additions and 253 deletions

View file

@ -6,6 +6,7 @@ from sqlglot.dialects.dialect import (
arrow_json_extract_sql,
format_time_lambda,
no_pivot_sql,
no_properties_sql,
no_safe_divide_sql,
no_tablesample_sql,
rename_func,
@ -68,6 +69,12 @@ def _struct_pack_sql(self, expression):
return f"STRUCT_PACK({', '.join(args)})"
def _datatype_sql(self, expression):
if expression.this == exp.DataType.Type.ARRAY:
return f"{self.expressions(expression, flat=True)}[]"
return self.datatype_sql(expression)
class DuckDB(Dialect):
class Tokenizer(Tokenizer):
KEYWORDS = {
@ -106,6 +113,8 @@ class DuckDB(Dialect):
}
class Generator(Generator):
STRUCT_DELIMITER = ("(", ")")
TRANSFORMS = {
**Generator.TRANSFORMS,
exp.ApproxDistinct: approx_count_distinct_sql,
@ -113,8 +122,9 @@ class DuckDB(Dialect):
exp.ArraySize: rename_func("ARRAY_LENGTH"),
exp.ArraySort: _array_sort_sql,
exp.ArraySum: rename_func("LIST_SUM"),
exp.DataType: _datatype_sql,
exp.DateAdd: _date_add,
exp.DateDiff: lambda self, e: f"""DATE_DIFF({self.sql(e, 'unit') or "'day'"}, {self.sql(e, 'expression')}, {self.sql(e, 'this')})""",
exp.DateDiff: lambda self, e: f"""DATE_DIFF({self.format_args(e.args.get("unit") or "'day'", e.expression, e.this)})""",
exp.DateStrToDate: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE)",
exp.DateToDi: lambda self, e: f"CAST(STRFTIME({self.sql(e, 'this')}, {DuckDB.dateint_format}) AS INT)",
exp.DiToDate: lambda self, e: f"CAST(STRPTIME(CAST({self.sql(e, 'this')} AS TEXT), {DuckDB.dateint_format}) AS DATE)",
@ -124,6 +134,7 @@ class DuckDB(Dialect):
exp.JSONBExtract: arrow_json_extract_sql,
exp.JSONBExtractScalar: arrow_json_extract_scalar_sql,
exp.Pivot: no_pivot_sql,
exp.Properties: no_properties_sql,
exp.RegexpLike: rename_func("REGEXP_MATCHES"),
exp.RegexpSplit: rename_func("STR_SPLIT_REGEX"),
exp.SafeDivide: no_safe_divide_sql,