diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-19 13:44:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-19 13:44:59 +0000 |
commit | ef2db38de92f2329c1c366318bddfc7e3dee8415 (patch) | |
tree | dee41de1eb0e05f2f6805b77df41a71b3aa66ec2 /sqlglot/dialects/teradata.py | |
parent | Adding upstream version 11.0.1. (diff) | |
download | sqlglot-ef2db38de92f2329c1c366318bddfc7e3dee8415.tar.xz sqlglot-ef2db38de92f2329c1c366318bddfc7e3dee8415.zip |
Adding upstream version 11.1.3.upstream/11.1.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/teradata.py')
-rw-r--r-- | sqlglot/dialects/teradata.py | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/sqlglot/dialects/teradata.py b/sqlglot/dialects/teradata.py index 123da04..e3eec71 100644 --- a/sqlglot/dialects/teradata.py +++ b/sqlglot/dialects/teradata.py @@ -1,11 +1,33 @@ from __future__ import annotations -from sqlglot import exp, generator, parser +from sqlglot import exp, generator, parser, tokens from sqlglot.dialects.dialect import Dialect from sqlglot.tokens import TokenType class Teradata(Dialect): + 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 = { + **tokens.Tokenizer.KEYWORDS, + "BYTEINT": TokenType.SMALLINT, + "SEL": TokenType.SELECT, + "INS": TokenType.INSERT, + "MOD": TokenType.MOD, + "LT": TokenType.LT, + "LE": TokenType.LTE, + "GT": TokenType.GT, + "GE": TokenType.GTE, + "^=": TokenType.NEQ, + "NE": TokenType.NEQ, + "NOT=": TokenType.NEQ, + "ST_GEOMETRY": TokenType.GEOMETRY, + } + + # teradata does not support % for modulus + SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS} + SINGLE_TOKENS.pop("%") + class Parser(parser.Parser): CHARSET_TRANSLATORS = { "GRAPHIC_TO_KANJISJIS", @@ -42,6 +64,14 @@ class Teradata(Dialect): "UNICODE_TO_UNICODE_NFKD", } + FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS} + FUNC_TOKENS.remove(TokenType.REPLACE) + + STATEMENT_PARSERS = { + **parser.Parser.STATEMENT_PARSERS, # type: ignore + TokenType.REPLACE: lambda self: self._parse_create(), + } + FUNCTION_PARSERS = { **parser.Parser.FUNCTION_PARSERS, # type: ignore "TRANSLATE": lambda self: self._parse_translate(self.STRICT_CAST), @@ -76,6 +106,11 @@ class Teradata(Dialect): ) class Generator(generator.Generator): + TYPE_MAPPING = { + **generator.Generator.TYPE_MAPPING, # type: ignore + exp.DataType.Type.GEOMETRY: "ST_GEOMETRY", + } + PROPERTIES_LOCATION = { **generator.Generator.PROPERTIES_LOCATION, # type: ignore exp.PartitionedByProperty: exp.Properties.Location.POST_INDEX, @@ -93,3 +128,11 @@ class Teradata(Dialect): where_sql = self.sql(expression, "where") sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}" return self.prepend_ctes(expression, sql) + + def mod_sql(self, expression: exp.Mod) -> str: + return self.binary(expression, "MOD") + + def datatype_sql(self, expression: exp.DataType) -> str: + type_sql = super().datatype_sql(expression) + prefix_sql = expression.args.get("prefix") + return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql |