Adding upstream version 20.3.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
5bd573dda1
commit
fd9de5e4cb
132 changed files with 55125 additions and 51576 deletions
|
@ -84,11 +84,35 @@ def _parse_date_diff(args: t.List) -> exp.Expression:
|
|||
return exp.DateDiff(this=seq_get(args, 2), expression=seq_get(args, 1), unit=seq_get(args, 0))
|
||||
|
||||
|
||||
def _parse_make_timestamp(args: t.List) -> exp.Expression:
|
||||
if len(args) == 1:
|
||||
return exp.UnixToTime(this=seq_get(args, 0), scale=exp.UnixToTime.MICROS)
|
||||
|
||||
return exp.TimestampFromParts(
|
||||
year=seq_get(args, 0),
|
||||
month=seq_get(args, 1),
|
||||
day=seq_get(args, 2),
|
||||
hour=seq_get(args, 3),
|
||||
min=seq_get(args, 4),
|
||||
sec=seq_get(args, 5),
|
||||
)
|
||||
|
||||
|
||||
def _struct_sql(self: DuckDB.Generator, expression: exp.Struct) -> str:
|
||||
args = [
|
||||
f"'{e.name or e.this.name}': {self.sql(e.expressions[0]) if isinstance(e, exp.Bracket) else self.sql(e, 'expression')}"
|
||||
for e in expression.expressions
|
||||
]
|
||||
args: t.List[str] = []
|
||||
for expr in expression.expressions:
|
||||
if isinstance(expr, exp.Alias):
|
||||
key = expr.alias
|
||||
value = expr.this
|
||||
else:
|
||||
key = expr.name or expr.this.name
|
||||
if isinstance(expr, exp.Bracket):
|
||||
value = expr.expressions[0]
|
||||
else:
|
||||
value = expr.expression
|
||||
|
||||
args.append(f"{self.sql(exp.Literal.string(key))}: {self.sql(value)}")
|
||||
|
||||
return f"{{{', '.join(args)}}}"
|
||||
|
||||
|
||||
|
@ -189,9 +213,7 @@ class DuckDB(Dialect):
|
|||
"LIST_REVERSE_SORT": _sort_array_reverse,
|
||||
"LIST_SORT": exp.SortArray.from_arg_list,
|
||||
"LIST_VALUE": exp.Array.from_arg_list,
|
||||
"MAKE_TIMESTAMP": lambda args: exp.UnixToTime(
|
||||
this=seq_get(args, 0), scale=exp.UnixToTime.MICROS
|
||||
),
|
||||
"MAKE_TIMESTAMP": _parse_make_timestamp,
|
||||
"MEDIAN": lambda args: exp.PercentileCont(
|
||||
this=seq_get(args, 0), expression=exp.Literal.number(0.5)
|
||||
),
|
||||
|
@ -339,6 +361,7 @@ class DuckDB(Dialect):
|
|||
exp.StrToUnix: lambda self, e: f"EPOCH(STRPTIME({self.sql(e, 'this')}, {self.format_time(e)}))",
|
||||
exp.Struct: _struct_sql,
|
||||
exp.Timestamp: no_timestamp_sql,
|
||||
exp.TimestampFromParts: rename_func("MAKE_TIMESTAMP"),
|
||||
exp.TimestampTrunc: timestamptrunc_sql,
|
||||
exp.TimeStrToDate: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE)",
|
||||
exp.TimeStrToTime: timestrtotime_sql,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue