Adding upstream version 16.2.1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
577b79f5a7
commit
d61627452f
106 changed files with 41940 additions and 40162 deletions
|
@ -1,18 +1,32 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import typing as t
|
||||
|
||||
from sqlglot import exp, generator, parser, tokens, transforms
|
||||
from sqlglot.dialects.dialect import (
|
||||
Dialect,
|
||||
format_time_lambda,
|
||||
max_or_greatest,
|
||||
min_or_least,
|
||||
)
|
||||
from sqlglot.dialects.dialect import Dialect, max_or_greatest, min_or_least
|
||||
from sqlglot.tokens import TokenType
|
||||
|
||||
|
||||
class Teradata(Dialect):
|
||||
TIME_MAPPING = {
|
||||
"Y": "%Y",
|
||||
"YYYY": "%Y",
|
||||
"YY": "%y",
|
||||
"MMMM": "%B",
|
||||
"MMM": "%b",
|
||||
"DD": "%d",
|
||||
"D": "%-d",
|
||||
"HH": "%H",
|
||||
"H": "%-H",
|
||||
"MM": "%M",
|
||||
"M": "%-M",
|
||||
"SS": "%S",
|
||||
"S": "%-S",
|
||||
"SSSSSS": "%f",
|
||||
"E": "%a",
|
||||
"EE": "%a",
|
||||
"EEE": "%a",
|
||||
"EEEE": "%A",
|
||||
}
|
||||
|
||||
class Tokenizer(tokens.Tokenizer):
|
||||
# https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance
|
||||
KEYWORDS = {
|
||||
|
@ -31,7 +45,7 @@ class Teradata(Dialect):
|
|||
"ST_GEOMETRY": TokenType.GEOMETRY,
|
||||
}
|
||||
|
||||
# teradata does not support % for modulus
|
||||
# Teradata does not support % as a modulo operator
|
||||
SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}
|
||||
SINGLE_TOKENS.pop("%")
|
||||
|
||||
|
@ -101,7 +115,7 @@ class Teradata(Dialect):
|
|||
|
||||
# FROM before SET in Teradata UPDATE syntax
|
||||
# https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
|
||||
def _parse_update(self) -> exp.Expression:
|
||||
def _parse_update(self) -> exp.Update:
|
||||
return self.expression(
|
||||
exp.Update,
|
||||
**{ # type: ignore
|
||||
|
@ -122,14 +136,6 @@ class Teradata(Dialect):
|
|||
|
||||
return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)
|
||||
|
||||
def _parse_cast(self, strict: bool) -> exp.Expression:
|
||||
cast = t.cast(exp.Cast, super()._parse_cast(strict))
|
||||
if cast.to.this == exp.DataType.Type.DATE and self._match(TokenType.FORMAT):
|
||||
return format_time_lambda(exp.TimeToStr, "teradata")(
|
||||
[cast.this, self._parse_string()]
|
||||
)
|
||||
return cast
|
||||
|
||||
class Generator(generator.Generator):
|
||||
JOIN_HINTS = False
|
||||
TABLE_HINTS = False
|
||||
|
@ -151,7 +157,7 @@ class Teradata(Dialect):
|
|||
exp.Max: max_or_greatest,
|
||||
exp.Min: min_or_least,
|
||||
exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
|
||||
exp.TimeToStr: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})",
|
||||
exp.StrToDate: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})",
|
||||
exp.ToChar: lambda self, e: self.function_fallback_sql(e),
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue