Adding upstream version 11.3.6.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
2f30828945
commit
d160fb48f7
46 changed files with 23416 additions and 22639 deletions
|
@ -16,6 +16,7 @@ from sqlglot.dialects.dialect import (
|
|||
)
|
||||
from sqlglot.expressions import Literal
|
||||
from sqlglot.helper import flatten, seq_get
|
||||
from sqlglot.parser import binary_range_parser
|
||||
from sqlglot.tokens import TokenType
|
||||
|
||||
|
||||
|
@ -111,7 +112,7 @@ def _parse_date_part(self):
|
|||
def _div0_to_if(args):
|
||||
cond = exp.EQ(this=seq_get(args, 1), expression=exp.Literal.number(0))
|
||||
true = exp.Literal.number(0)
|
||||
false = exp.FloatDiv(this=seq_get(args, 0), expression=seq_get(args, 1))
|
||||
false = exp.Div(this=seq_get(args, 0), expression=seq_get(args, 1))
|
||||
return exp.If(this=cond, true=true, false=false)
|
||||
|
||||
|
||||
|
@ -173,26 +174,33 @@ class Snowflake(Dialect):
|
|||
FUNCTIONS = {
|
||||
**parser.Parser.FUNCTIONS,
|
||||
"ARRAYAGG": exp.ArrayAgg.from_arg_list,
|
||||
"ARRAY_CONSTRUCT": exp.Array.from_arg_list,
|
||||
"ARRAY_TO_STRING": exp.ArrayJoin.from_arg_list,
|
||||
"DATEADD": lambda args: exp.DateAdd(
|
||||
this=seq_get(args, 2),
|
||||
expression=seq_get(args, 1),
|
||||
unit=seq_get(args, 0),
|
||||
),
|
||||
"DATEDIFF": lambda args: exp.DateDiff(
|
||||
this=seq_get(args, 2),
|
||||
expression=seq_get(args, 1),
|
||||
unit=seq_get(args, 0),
|
||||
),
|
||||
"DATE_TRUNC": lambda args: exp.DateTrunc(
|
||||
unit=exp.Literal.string(seq_get(args, 0).name), # type: ignore
|
||||
this=seq_get(args, 1),
|
||||
),
|
||||
"DECODE": exp.Matches.from_arg_list,
|
||||
"DIV0": _div0_to_if,
|
||||
"IFF": exp.If.from_arg_list,
|
||||
"TO_ARRAY": exp.Array.from_arg_list,
|
||||
"TO_TIMESTAMP": _snowflake_to_timestamp,
|
||||
"ARRAY_CONSTRUCT": exp.Array.from_arg_list,
|
||||
"RLIKE": exp.RegexpLike.from_arg_list,
|
||||
"DECODE": exp.Matches.from_arg_list,
|
||||
"OBJECT_CONSTRUCT": parser.parse_var_map,
|
||||
"ZEROIFNULL": _zeroifnull_to_if,
|
||||
"NULLIFZERO": _nullifzero_to_if,
|
||||
"OBJECT_CONSTRUCT": parser.parse_var_map,
|
||||
"RLIKE": exp.RegexpLike.from_arg_list,
|
||||
"SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)),
|
||||
"TO_ARRAY": exp.Array.from_arg_list,
|
||||
"TO_VARCHAR": exp.ToChar.from_arg_list,
|
||||
"TO_TIMESTAMP": _snowflake_to_timestamp,
|
||||
"ZEROIFNULL": _zeroifnull_to_if,
|
||||
}
|
||||
|
||||
FUNCTION_PARSERS = {
|
||||
|
@ -218,12 +226,8 @@ class Snowflake(Dialect):
|
|||
|
||||
RANGE_PARSERS = {
|
||||
**parser.Parser.RANGE_PARSERS, # type: ignore
|
||||
TokenType.LIKE_ANY: lambda self, this: self._parse_escape(
|
||||
self.expression(exp.LikeAny, this=this, expression=self._parse_bitwise())
|
||||
),
|
||||
TokenType.ILIKE_ANY: lambda self, this: self._parse_escape(
|
||||
self.expression(exp.ILikeAny, this=this, expression=self._parse_bitwise())
|
||||
),
|
||||
TokenType.LIKE_ANY: binary_range_parser(exp.LikeAny),
|
||||
TokenType.ILIKE_ANY: binary_range_parser(exp.ILikeAny),
|
||||
}
|
||||
|
||||
ALTER_PARSERS = {
|
||||
|
@ -232,8 +236,6 @@ class Snowflake(Dialect):
|
|||
"SET": lambda self: self._parse_alter_table_set_tag(),
|
||||
}
|
||||
|
||||
INTEGER_DIVISION = False
|
||||
|
||||
def _parse_alter_table_set_tag(self, unset: bool = False) -> exp.Expression:
|
||||
self._match_text_seq("TAG")
|
||||
parser = t.cast(t.Callable, self._parse_id_var if unset else self._parse_conjunction)
|
||||
|
@ -266,7 +268,6 @@ class Snowflake(Dialect):
|
|||
|
||||
class Generator(generator.Generator):
|
||||
PARAMETER_TOKEN = "$"
|
||||
INTEGER_DIVISION = False
|
||||
MATCHED_BY_SOURCE = False
|
||||
|
||||
TRANSFORMS = {
|
||||
|
@ -289,6 +290,7 @@ class Snowflake(Dialect):
|
|||
exp.TimeStrToTime: timestrtotime_sql,
|
||||
exp.TimeToUnix: lambda self, e: f"EXTRACT(epoch_second FROM {self.sql(e, 'this')})",
|
||||
exp.Trim: lambda self, e: self.func("TRIM", e.this, e.expression),
|
||||
exp.ToChar: lambda self, e: self.function_fallback_sql(e),
|
||||
exp.TsOrDsToDate: ts_or_ds_to_date_sql("snowflake"),
|
||||
exp.UnixToTime: _unix_to_time_sql,
|
||||
exp.DayOfWeek: rename_func("DAYOFWEEK"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue