Adding upstream version 25.29.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
dfac4c492f
commit
c61927f460
97 changed files with 64720 additions and 61752 deletions
|
@ -22,7 +22,11 @@ from sqlglot.dialects.dialect import (
|
|||
timestrtotime_sql,
|
||||
var_map_sql,
|
||||
map_date_part,
|
||||
no_safe_divide_sql,
|
||||
no_timestamp_sql,
|
||||
timestampdiff_sql,
|
||||
)
|
||||
from sqlglot.generator import unsupported_args
|
||||
from sqlglot.helper import flatten, is_float, is_int, seq_get
|
||||
from sqlglot.tokens import TokenType
|
||||
|
||||
|
@ -329,9 +333,6 @@ class Snowflake(Dialect):
|
|||
"LEN": lambda args: exp.Length(this=seq_get(args, 0), binary=True),
|
||||
"LENGTH": lambda args: exp.Length(this=seq_get(args, 0), binary=True),
|
||||
"LISTAGG": exp.GroupConcat.from_arg_list,
|
||||
"MEDIAN": lambda args: exp.PercentileCont(
|
||||
this=seq_get(args, 0), expression=exp.Literal.number(0.5)
|
||||
),
|
||||
"NULLIFZERO": _build_if_from_nullifzero,
|
||||
"OBJECT_CONSTRUCT": _build_object_construct,
|
||||
"REGEXP_REPLACE": _build_regexp_replace,
|
||||
|
@ -351,6 +352,8 @@ class Snowflake(Dialect):
|
|||
"TIMESTAMPDIFF": _build_datediff,
|
||||
"TIMESTAMPFROMPARTS": build_timestamp_from_parts,
|
||||
"TIMESTAMP_FROM_PARTS": build_timestamp_from_parts,
|
||||
"TIMESTAMPNTZFROMPARTS": build_timestamp_from_parts,
|
||||
"TIMESTAMP_NTZ_FROM_PARTS": build_timestamp_from_parts,
|
||||
"TRY_PARSE_JSON": lambda args: exp.ParseJSON(this=seq_get(args, 0), safe=True),
|
||||
"TRY_TO_DATE": _build_datetime("TRY_TO_DATE", exp.DataType.Type.DATE, safe=True),
|
||||
"TRY_TO_TIMESTAMP": _build_datetime(
|
||||
|
@ -766,6 +769,7 @@ class Snowflake(Dialect):
|
|||
ARRAY_CONCAT_IS_VAR_LEN = False
|
||||
SUPPORTS_CONVERT_TIMEZONE = True
|
||||
EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE = False
|
||||
SUPPORTS_MEDIAN = True
|
||||
|
||||
TRANSFORMS = {
|
||||
**generator.Generator.TRANSFORMS,
|
||||
|
@ -782,6 +786,8 @@ class Snowflake(Dialect):
|
|||
exp.Create: transforms.preprocess([_flatten_structured_types_unless_iceberg]),
|
||||
exp.DateAdd: date_delta_sql("DATEADD"),
|
||||
exp.DateDiff: date_delta_sql("DATEDIFF"),
|
||||
exp.DatetimeAdd: date_delta_sql("TIMESTAMPADD"),
|
||||
exp.DatetimeDiff: timestampdiff_sql,
|
||||
exp.DateStrToDate: datestrtodate_sql,
|
||||
exp.DayOfMonth: rename_func("DAYOFMONTH"),
|
||||
exp.DayOfWeek: rename_func("DAYOFWEEK"),
|
||||
|
@ -796,7 +802,6 @@ class Snowflake(Dialect):
|
|||
),
|
||||
exp.GroupConcat: rename_func("LISTAGG"),
|
||||
exp.If: if_sql(name="IFF", false_value="NULL"),
|
||||
exp.JSONExtract: lambda self, e: self.func("GET_PATH", e.this, e.expression),
|
||||
exp.JSONExtractScalar: lambda self, e: self.func(
|
||||
"JSON_EXTRACT_PATH_TEXT", e.this, e.expression
|
||||
),
|
||||
|
@ -828,14 +833,18 @@ class Snowflake(Dialect):
|
|||
_unnest_generate_date_array,
|
||||
]
|
||||
),
|
||||
exp.SafeDivide: lambda self, e: no_safe_divide_sql(self, e, "IFF"),
|
||||
exp.SHA: rename_func("SHA1"),
|
||||
exp.StarMap: rename_func("OBJECT_CONSTRUCT"),
|
||||
exp.StartsWith: rename_func("STARTSWITH"),
|
||||
exp.StrPosition: lambda self, e: self.func(
|
||||
"POSITION", e.args.get("substr"), e.this, e.args.get("position")
|
||||
),
|
||||
exp.StrToDate: lambda self, e: self.func("DATE", e.this, self.format_time(e)),
|
||||
exp.Stuff: rename_func("INSERT"),
|
||||
exp.TimeAdd: date_delta_sql("TIMEADD"),
|
||||
exp.Timestamp: no_timestamp_sql,
|
||||
exp.TimestampAdd: date_delta_sql("TIMESTAMPADD"),
|
||||
exp.TimestampDiff: lambda self, e: self.func(
|
||||
"TIMESTAMPDIFF", e.unit, e.expression, e.this
|
||||
),
|
||||
|
@ -1061,7 +1070,7 @@ class Snowflake(Dialect):
|
|||
|
||||
return self.func("OBJECT_CONSTRUCT", *flatten(zip(keys, values)))
|
||||
|
||||
@generator.unsupported_args("weight", "accuracy")
|
||||
@unsupported_args("weight", "accuracy")
|
||||
def approxquantile_sql(self, expression: exp.ApproxQuantile) -> str:
|
||||
return self.func("APPROX_PERCENTILE", expression.this, expression.args.get("quantile"))
|
||||
|
||||
|
@ -1082,3 +1091,22 @@ class Snowflake(Dialect):
|
|||
return self.func(
|
||||
f"{safe_prefix}TO_TIMESTAMP", expression.this, self.format_time(expression)
|
||||
)
|
||||
|
||||
def timestampsub_sql(self, expression: exp.TimestampSub):
|
||||
return self.sql(
|
||||
exp.TimestampAdd(
|
||||
this=expression.this,
|
||||
expression=expression.expression * -1,
|
||||
unit=expression.unit,
|
||||
)
|
||||
)
|
||||
|
||||
def jsonextract_sql(self, expression: exp.JSONExtract):
|
||||
this = expression.this
|
||||
|
||||
# JSON strings are valid coming from other dialects such as BQ
|
||||
return self.func(
|
||||
"GET_PATH",
|
||||
exp.ParseJSON(this=this) if this.is_string else this,
|
||||
expression.expression,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue