Merging upstream version 20.9.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
9421b254ec
commit
37a231f554
144 changed files with 78309 additions and 59609 deletions
|
@ -9,8 +9,8 @@ from sqlglot.dialects.dialect import (
|
|||
concat_ws_to_dpipe_sql,
|
||||
date_delta_sql,
|
||||
generatedasidentitycolumnconstraint_sql,
|
||||
no_tablesample_sql,
|
||||
rename_func,
|
||||
ts_or_ds_to_date_sql,
|
||||
)
|
||||
from sqlglot.dialects.postgres import Postgres
|
||||
from sqlglot.helper import seq_get
|
||||
|
@ -123,6 +123,27 @@ class Redshift(Postgres):
|
|||
self._retreat(index)
|
||||
return None
|
||||
|
||||
def _parse_query_modifiers(
|
||||
self, this: t.Optional[exp.Expression]
|
||||
) -> t.Optional[exp.Expression]:
|
||||
this = super()._parse_query_modifiers(this)
|
||||
|
||||
if this:
|
||||
refs = set()
|
||||
|
||||
for i, join in enumerate(this.args.get("joins", [])):
|
||||
refs.add(
|
||||
(
|
||||
this.args["from"] if i == 0 else this.args["joins"][i - 1]
|
||||
).alias_or_name.lower()
|
||||
)
|
||||
table = join.this
|
||||
|
||||
if isinstance(table, exp.Table):
|
||||
if table.parts[0].name.lower() in refs:
|
||||
table.replace(table.to_column())
|
||||
return this
|
||||
|
||||
class Tokenizer(Postgres.Tokenizer):
|
||||
BIT_STRINGS = []
|
||||
HEX_STRINGS = []
|
||||
|
@ -144,11 +165,11 @@ class Redshift(Postgres):
|
|||
|
||||
class Generator(Postgres.Generator):
|
||||
LOCKING_READS_SUPPORTED = False
|
||||
RENAME_TABLE_WITH_DB = False
|
||||
QUERY_HINTS = False
|
||||
VALUES_AS_TABLE = False
|
||||
TZ_TO_WITH_TIME_ZONE = True
|
||||
NVL2_SUPPORTED = True
|
||||
LAST_DAY_SUPPORTS_DATE_PART = False
|
||||
|
||||
TYPE_MAPPING = {
|
||||
**Postgres.Generator.TYPE_MAPPING,
|
||||
|
@ -184,9 +205,9 @@ class Redshift(Postgres):
|
|||
[transforms.eliminate_distinct_on, transforms.eliminate_semi_and_anti_joins]
|
||||
),
|
||||
exp.SortKeyProperty: lambda self, e: f"{'COMPOUND ' if e.args['compound'] else ''}SORTKEY({self.format_args(*e.this)})",
|
||||
exp.TableSample: no_tablesample_sql,
|
||||
exp.TsOrDsAdd: date_delta_sql("DATEADD"),
|
||||
exp.TsOrDsDiff: date_delta_sql("DATEDIFF"),
|
||||
exp.TsOrDsToDate: ts_or_ds_to_date_sql("redshift"),
|
||||
}
|
||||
|
||||
# Postgres maps exp.Pivot to no_pivot_sql, but Redshift support pivots
|
||||
|
@ -198,6 +219,9 @@ class Redshift(Postgres):
|
|||
# Redshift supports ANY_VALUE(..)
|
||||
TRANSFORMS.pop(exp.AnyValue)
|
||||
|
||||
# Redshift supports LAST_DAY(..)
|
||||
TRANSFORMS.pop(exp.LastDay)
|
||||
|
||||
RESERVED_KEYWORDS = {*Postgres.Generator.RESERVED_KEYWORDS, "snapshot", "type"}
|
||||
|
||||
def with_properties(self, properties: exp.Properties) -> str:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue