1
0
Fork 0

Adding upstream version 25.6.1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 21:42:48 +01:00
parent 4e506fbac7
commit f9dae8e951
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
69 changed files with 46817 additions and 45778 deletions

View file

@ -116,17 +116,24 @@ def _build_make_timestamp(args: t.List) -> exp.Expression:
def _struct_sql(self: DuckDB.Generator, expression: exp.Struct) -> str:
args: t.List[str] = []
# BigQuery allows inline construction such as "STRUCT<a STRING, b INTEGER>('str', 1)" which is
# canonicalized to "ROW('str', 1) AS STRUCT(a TEXT, b INT)" in DuckDB
is_struct_cast = expression.find_ancestor(exp.Cast)
for i, expr in enumerate(expression.expressions):
if isinstance(expr, exp.PropertyEQ):
key = expr.name
value = expr.expression
is_property_eq = isinstance(expr, exp.PropertyEQ)
value = expr.expression if is_property_eq else expr
if is_struct_cast:
args.append(self.sql(value))
else:
key = f"_{i}"
value = expr
key = expr.name if is_property_eq else f"_{i}"
args.append(f"{self.sql(exp.Literal.string(key))}: {self.sql(value)}")
args.append(f"{self.sql(exp.Literal.string(key))}: {self.sql(value)}")
csv_args = ", ".join(args)
return f"{{{', '.join(args)}}}"
return f"ROW({csv_args})" if is_struct_cast else f"{{{csv_args}}}"
def _datatype_sql(self: DuckDB.Generator, expression: exp.DataType) -> str:
@ -172,6 +179,7 @@ class DuckDB(Dialect):
SAFE_DIVISION = True
INDEX_OFFSET = 1
CONCAT_COALESCE = True
SUPPORTS_ORDER_BY_ALL = True
# https://duckdb.org/docs/sql/introduction.html#creating-a-new-table
NORMALIZATION_STRATEGY = NormalizationStrategy.CASE_INSENSITIVE
@ -381,6 +389,7 @@ class DuckDB(Dialect):
SUPPORTS_TO_NUMBER = False
COPY_HAS_INTO_KEYWORD = False
STAR_EXCEPT = "EXCLUDE"
PAD_FILL_PATTERN_IS_REQUIRED = True
TRANSFORMS = {
**generator.Generator.TRANSFORMS,
@ -448,6 +457,8 @@ class DuckDB(Dialect):
),
exp.RegexpLike: rename_func("REGEXP_MATCHES"),
exp.RegexpSplit: rename_func("STR_SPLIT_REGEX"),
exp.Return: lambda self, e: self.sql(e, "this"),
exp.ReturnsProperty: lambda self, e: "TABLE" if isinstance(e.this, exp.Schema) else "",
exp.Rand: rename_func("RANDOM"),
exp.SafeDivide: no_safe_divide_sql,
exp.Split: rename_func("STR_SPLIT"),
@ -609,6 +620,7 @@ class DuckDB(Dialect):
# can be transpiled to DuckDB, so we explicitly override them accordingly
PROPERTIES_LOCATION[exp.LikeProperty] = exp.Properties.Location.POST_SCHEMA
PROPERTIES_LOCATION[exp.TemporaryProperty] = exp.Properties.Location.POST_CREATE
PROPERTIES_LOCATION[exp.ReturnsProperty] = exp.Properties.Location.POST_ALIAS
def strtotime_sql(self, expression: exp.StrToTime) -> str:
if expression.args.get("safe"):