Adding upstream version 15.2.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
bb75596aa9
commit
577b79f5a7
81 changed files with 40321 additions and 37940 deletions
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
import typing as t
|
||||
|
||||
from sqlglot import exp, transforms
|
||||
from sqlglot.dialects.dialect import rename_func
|
||||
from sqlglot.dialects.postgres import Postgres
|
||||
from sqlglot.helper import seq_get
|
||||
from sqlglot.tokens import TokenType
|
||||
|
@ -24,26 +25,29 @@ class Redshift(Postgres):
|
|||
FUNCTIONS = {
|
||||
**Postgres.Parser.FUNCTIONS,
|
||||
"DATEADD": lambda args: exp.DateAdd(
|
||||
this=seq_get(args, 2),
|
||||
this=exp.TsOrDsToDate(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),
|
||||
this=exp.TsOrDsToDate(this=seq_get(args, 2)),
|
||||
expression=exp.TsOrDsToDate(this=seq_get(args, 1)),
|
||||
unit=seq_get(args, 0),
|
||||
),
|
||||
"NVL": exp.Coalesce.from_arg_list,
|
||||
"STRTOL": exp.FromBase.from_arg_list,
|
||||
}
|
||||
|
||||
CONVERT_TYPE_FIRST = True
|
||||
|
||||
def _parse_types(self, check_func: bool = False) -> t.Optional[exp.Expression]:
|
||||
this = super()._parse_types(check_func=check_func)
|
||||
def _parse_types(
|
||||
self, check_func: bool = False, schema: bool = False
|
||||
) -> t.Optional[exp.Expression]:
|
||||
this = super()._parse_types(check_func=check_func, schema=schema)
|
||||
|
||||
if (
|
||||
isinstance(this, exp.DataType)
|
||||
and this.this == exp.DataType.Type.VARCHAR
|
||||
and this.is_type("varchar")
|
||||
and this.expressions
|
||||
and this.expressions[0].this == exp.column("MAX")
|
||||
):
|
||||
|
@ -99,10 +103,12 @@ class Redshift(Postgres):
|
|||
),
|
||||
exp.DistKeyProperty: lambda self, e: f"DISTKEY({e.name})",
|
||||
exp.DistStyleProperty: lambda self, e: self.naked_property(e),
|
||||
exp.FromBase: rename_func("STRTOL"),
|
||||
exp.JSONExtract: _json_sql,
|
||||
exp.JSONExtractScalar: _json_sql,
|
||||
exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
|
||||
exp.SortKeyProperty: lambda self, e: f"{'COMPOUND ' if e.args['compound'] else ''}SORTKEY({self.format_args(*e.this)})",
|
||||
exp.TsOrDsToDate: lambda self, e: self.sql(e.this),
|
||||
}
|
||||
|
||||
# Postgres maps exp.Pivot to no_pivot_sql, but Redshift support pivots
|
||||
|
@ -158,7 +164,7 @@ class Redshift(Postgres):
|
|||
without precision we convert it to `VARCHAR(max)` and if it does have precision then we just convert
|
||||
`TEXT` to `VARCHAR`.
|
||||
"""
|
||||
if expression.this == exp.DataType.Type.TEXT:
|
||||
if expression.is_type("text"):
|
||||
expression = expression.copy()
|
||||
expression.set("this", exp.DataType.Type.VARCHAR)
|
||||
precision = expression.args.get("expressions")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue