From 908e5129123463bb8511dd06b66f963b6541dc9f Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Mon, 7 Aug 2023 14:13:05 +0800 Subject: [PATCH 01/12] add doris dialect --- sqlglot/dialects/__init__.py | 1 + sqlglot/dialects/dialect.py | 1 + sqlglot/dialects/doris.py | 166 +++++++++++++++++++++++++++++++++++ tests/dialects/test_doris.py | 20 +++++ 4 files changed, 188 insertions(+) create mode 100644 sqlglot/dialects/doris.py create mode 100644 tests/dialects/test_doris.py diff --git a/sqlglot/dialects/__init__.py b/sqlglot/dialects/__init__.py index fc342621ae..1e96c1b329 100644 --- a/sqlglot/dialects/__init__.py +++ b/sqlglot/dialects/__init__.py @@ -77,3 +77,4 @@ class Generator(Generator): from sqlglot.dialects.teradata import Teradata from sqlglot.dialects.trino import Trino from sqlglot.dialects.tsql import TSQL +from sqlglot.dialects.doris import Doris diff --git a/sqlglot/dialects/dialect.py b/sqlglot/dialects/dialect.py index bae7bad203..b23a697c8c 100644 --- a/sqlglot/dialects/dialect.py +++ b/sqlglot/dialects/dialect.py @@ -39,6 +39,7 @@ class Dialects(str, Enum): TERADATA = "teradata" TRINO = "trino" TSQL = "tsql" + Doris = "doris" class _Dialect(type): diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py new file mode 100644 index 0000000000..2125d1c001 --- /dev/null +++ b/sqlglot/dialects/doris.py @@ -0,0 +1,166 @@ +from __future__ import annotations +import typing as t +from sqlglot import exp, generator, parser, tokens, transforms +from sqlglot.dialects.dialect import ( + approx_count_distinct_sql, + arrow_json_extract_sql, + rename_func, +) +from sqlglot.dialects.mysql import MySQL +from sqlglot.helper import seq_get +from sqlglot.tokens import TokenType + +# (FuncType, Multiplier) +DATE_DELTA_INTERVAL = { + "YEAR": ("ADD_MONTHS", 12), + "MONTH": ("ADD_MONTHS", 1), + "QUARTER": ("ADD_MONTHS", 3), + "WEEK": ("DATE_ADD", 7), + "DAY": ("DATE_ADD", 1), +} + +# TRANSFORMS.pop(exp.DateTrunc) +def _add_date_sql(self: generator.Generator, expression: exp.DateAdd | exp.DateSub) -> str: + unit = expression.text("unit").upper() + func, multiplier = DATE_DELTA_INTERVAL.get(unit, ("DATE_ADD", 1)) + + if isinstance(expression, exp.DateSub): + multiplier *= -1 + + if expression.expression.is_number: + modified_increment = exp.Literal.number(int(expression.text("expression")) * multiplier) + else: + modified_increment = expression.expression + if multiplier != 1: + modified_increment = exp.Mul( # type: ignore + this=modified_increment, expression=exp.Literal.number(multiplier) + ) + + return self.func(func, expression.this, modified_increment) + +def _to_date_sql(self: generator.Generator, expression: exp.TsOrDsToDate) -> str: + this = self.sql(expression, "this") + time_format = self.format_time(expression) + # if time_format and time_format not in (Doris.TIME_FORMAT, Doris.DATE_FORMAT): + # return f"TO_DATE({this}, {time_format})" + return f"TO_DATE({this})" + +def _str_to_date_sql(self: generator.Generator, expression: exp.StrToDate) -> str: + this = self.sql(expression, "this") + time_format = self.format_time(expression) + if time_format not in (Doris.TIME_FORMAT, Doris.DATE_FORMAT): + this = f"FROM_UNIXTIME(UNIX_TIMESTAMP({this}, {time_format}))" + return f"CAST({this} AS DATE)" + + +def _str_to_time_sql(self: generator.Generator, expression: exp.StrToTime) -> str: + this = self.sql(expression, "this") + time_format = self.format_time(expression) + if time_format not in (Doris.TIME_FORMAT, Doris.DATE_FORMAT): + this = f"FROM_UNIXTIME(UNIX_TIMESTAMP({this}, {time_format}))" + return f"CAST({this} AS TIMESTAMP)" + +def _str_to_unix_sql(self: generator.Generator, expression: exp.StrToUnix) -> str: + return self.func("UNIX_TIMESTAMP", expression.this, _time_format(self, expression)) + +def _time_format( + self: generator.Generator, expression: exp.UnixToStr | exp.StrToUnix +) -> t.Optional[str]: + time_format = self.format_time(expression) + if time_format == Doris.TIME_FORMAT: + return None + return time_format + +class Doris(MySQL): + + DATE_FORMAT = "'yyyy-MM-dd'" + DATEINT_FORMAT = "'yyyyMMdd'" + TIME_FORMAT = "'yyyy-MM-dd HH:mm:ss'" + + # https://prestodb.io/docs/current/functions/datetime.html#mysql-date-functions + TIME_MAPPING = { + "%M": "%B", + "%c": "%-m", + "%e": "%-d", + "%h": "%I", + "%i": "%M", + "%s": "%S", + "%S": "%S", + "%u": "%W", + "%k": "%-H", + "%l": "%-I", + "%T": "%H:%M:%S", + "%W": "%a", + } + class Parser(MySQL.Parser): + FUNCTIONS = { + **MySQL.Parser.FUNCTIONS, + "DATE_TRUNC": lambda args: exp.TimestampTrunc( + this=seq_get(args, 1), unit=seq_get(args, 0) + ), + "SYSDATE": TokenType.CURRENT_TIMESTAMP, + } + + class Generator(MySQL.Generator): + CAST_MAPPING = { + exp.DataType.Type.BIGINT: "BIGINT", + exp.DataType.Type.BOOLEAN: "BOOLEAN", + exp.DataType.Type.INT: "INT", + exp.DataType.Type.TEXT: "STRING", + exp.DataType.Type.UBIGINT: "UNSIGNED", + exp.DataType.Type.VARCHAR: "VARCHAR", + exp.DataType.Type.BINARY: "STRING", + exp.DataType.Type.BIT: "BOOLEAN", + exp.DataType.Type.DATETIME64: "DATETIME", + exp.DataType.Type.ENUM: "STRING", + exp.DataType.Type.IMAGE: "UNSUPPORTED", + exp.DataType.Type.INT128: "LARGEINT", + exp.DataType.Type.INT256: "STRING", + exp.DataType.Type.UINT128: "STRING", + exp.DataType.Type.JSONB: "JSON", + exp.DataType.Type.LONGTEXT: "STRING", + exp.DataType.Type.MONEY: "DECIMAL", + } + + TYPE_MAPPING = { + **MySQL.Generator.TYPE_MAPPING, + exp.DataType.Type.TEXT: "STRING", + exp.DataType.Type.TIMESTAMP: "DATETIME", + exp.DataType.Type.TIMESTAMPTZ: "DATETIME", + } + + TRANSFORMS = { + **MySQL.Generator.TRANSFORMS, + exp.ApproxDistinct: approx_count_distinct_sql, + exp.JSONExtractScalar: arrow_json_extract_sql, + exp.JSONExtract: arrow_json_extract_sql, + exp.DateDiff: rename_func("DATEDIFF"), + exp.RegexpLike: rename_func("REGEXP"), + exp.Coalesce: rename_func("NVL"), + exp.CurrentTimestamp: lambda self, e: "NOW()", + exp.TimeToStr: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", + # exp.StrToUnix: rename_func("UNIX_TIMESTAMP"), + exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})", + exp.TimestampTrunc: lambda self, e: self.func( + "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this + ), + exp.TimeStrToDate: rename_func("TO_DATE"), + # exp.UnixToStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}, {self.format_time(e)})", + exp.UnixToStr: lambda self, e: self.func( + "FROM_UNIXTIME", e.this, _time_format(self, e) + ), + exp.UnixToTime: rename_func("FROM_UNIXTIME"), + exp.ArrayAgg: rename_func("COLLECT_LIST"), + exp.SetAgg: rename_func("COLLECT_SET"), + exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", # Only for day level + exp.TsOrDsToDate: _to_date_sql, + exp.StrToDate: _str_to_date_sql, + exp.StrToTime: _str_to_time_sql, + # exp.CurrentDate: rename_func("NOW"), + # exp.StrToUnix: _str_to_unix_sql, + + } + # TRANSFORMS.pop(exp.UnixToStr) + + + diff --git a/tests/dialects/test_doris.py b/tests/dialects/test_doris.py new file mode 100644 index 0000000000..63325a6b4d --- /dev/null +++ b/tests/dialects/test_doris.py @@ -0,0 +1,20 @@ +from tests.dialects.test_dialect import Validator + + +class TestDoris(Validator): + dialect = "doris" + + def test_identity(self): + self.validate_identity("SELECT CAST(`a`.`b` AS INT) FROM foo") + self.validate_identity("SELECT APPROX_COUNT_DISTINCT(a) FROM x") + + def test_time(self): + self.validate_identity("TIMESTAMP('2022-01-01')") + + def test_regex(self): + self.validate_all( + "SELECT REGEXP_LIKE(abc, '%foo%')", + write={ + "doris": "SELECT REGEXP(abc, '%foo%')", + }, + ) From c2e1c3c819ac34972b23329c09c10c6dad784634 Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Mon, 7 Aug 2023 17:33:30 +0800 Subject: [PATCH 02/12] fix doris dialect --- sqlglot/dialects/doris.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index 2125d1c001..62cfd9d62f 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -5,6 +5,7 @@ approx_count_distinct_sql, arrow_json_extract_sql, rename_func, + var_map_sql, ) from sqlglot.dialects.mysql import MySQL from sqlglot.helper import seq_get @@ -71,6 +72,23 @@ def _time_format( return None return time_format +def var_map_sql( + self, expression: exp.Map | exp.VarMap, map_func_name: str = "ARRAY_MAP" +) -> str: + keys = expression.args["keys"] + values = expression.args["values"] + + if not isinstance(keys, exp.Array) or not isinstance(values, exp.Array): + self.unsupported("Cannot convert array columns into map.") + return self.func(map_func_name, keys, values) + + args = [] + for key, value in zip(keys.expressions, values.expressions): + args.append(self.sql(key)) + args.append(self.sql(value)) + + return self.func(*args,map_func_name) + class Doris(MySQL): DATE_FORMAT = "'yyyy-MM-dd'" @@ -80,6 +98,7 @@ class Doris(MySQL): # https://prestodb.io/docs/current/functions/datetime.html#mysql-date-functions TIME_MAPPING = { "%M": "%B", + "%m": "%%-M", "%c": "%-m", "%e": "%-d", "%h": "%I", @@ -89,8 +108,12 @@ class Doris(MySQL): "%u": "%W", "%k": "%-H", "%l": "%-I", - "%T": "%H:%M:%S", "%W": "%a", + "%Y": "%Y", + "%d": "%%-d", + "%H": "%%-H", + "%s": "%%-S", + "%": "%%", } class Parser(MySQL.Parser): FUNCTIONS = { @@ -138,6 +161,7 @@ class Generator(MySQL.Generator): exp.RegexpLike: rename_func("REGEXP"), exp.Coalesce: rename_func("NVL"), exp.CurrentTimestamp: lambda self, e: "NOW()", + # exp.CurrentTime: lambda self, e: "NOW()", exp.TimeToStr: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", # exp.StrToUnix: rename_func("UNIX_TIMESTAMP"), exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})", @@ -156,11 +180,16 @@ class Generator(MySQL.Generator): exp.TsOrDsToDate: _to_date_sql, exp.StrToDate: _str_to_date_sql, exp.StrToTime: _str_to_time_sql, - # exp.CurrentDate: rename_func("NOW"), + exp.Map: rename_func("ARRAY_MAP"), + exp.VarMap: var_map_sql, + exp.RegexpSplit: rename_func("SPLIT_BY_STRING"), + exp.Split: rename_func("SPLIT_BY_STRING"), + exp.Quantile: rename_func("PERCENTILE"), + exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), # exp.StrToUnix: _str_to_unix_sql, } - # TRANSFORMS.pop(exp.UnixToStr) + # TRANSFORMS.pop(exp.Map) From f8610af4b6df81e0d35bef4884526d85daaea7a9 Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Mon, 7 Aug 2023 17:59:44 +0800 Subject: [PATCH 03/12] fix doris dialect --- sqlglot/dialects/doris.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index 62cfd9d62f..d669cde7fa 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -5,7 +5,6 @@ approx_count_distinct_sql, arrow_json_extract_sql, rename_func, - var_map_sql, ) from sqlglot.dialects.mysql import MySQL from sqlglot.helper import seq_get @@ -128,7 +127,6 @@ class Generator(MySQL.Generator): CAST_MAPPING = { exp.DataType.Type.BIGINT: "BIGINT", exp.DataType.Type.BOOLEAN: "BOOLEAN", - exp.DataType.Type.INT: "INT", exp.DataType.Type.TEXT: "STRING", exp.DataType.Type.UBIGINT: "UNSIGNED", exp.DataType.Type.VARCHAR: "VARCHAR", @@ -168,7 +166,7 @@ class Generator(MySQL.Generator): exp.TimestampTrunc: lambda self, e: self.func( "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this ), - exp.TimeStrToDate: rename_func("TO_DATE"), + exp.TimeStrToDate: rename_func("STR_TO_DATE"), # exp.UnixToStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}, {self.format_time(e)})", exp.UnixToStr: lambda self, e: self.func( "FROM_UNIXTIME", e.this, _time_format(self, e) From 1c195ffcf192b18a40d75e8cb985941dda2af3bb Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Mon, 7 Aug 2023 18:04:48 +0800 Subject: [PATCH 04/12] fix doris dialect --- sqlglot/dialects/doris.py | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index d669cde7fa..dd1adc0559 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -124,24 +124,7 @@ class Parser(MySQL.Parser): } class Generator(MySQL.Generator): - CAST_MAPPING = { - exp.DataType.Type.BIGINT: "BIGINT", - exp.DataType.Type.BOOLEAN: "BOOLEAN", - exp.DataType.Type.TEXT: "STRING", - exp.DataType.Type.UBIGINT: "UNSIGNED", - exp.DataType.Type.VARCHAR: "VARCHAR", - exp.DataType.Type.BINARY: "STRING", - exp.DataType.Type.BIT: "BOOLEAN", - exp.DataType.Type.DATETIME64: "DATETIME", - exp.DataType.Type.ENUM: "STRING", - exp.DataType.Type.IMAGE: "UNSUPPORTED", - exp.DataType.Type.INT128: "LARGEINT", - exp.DataType.Type.INT256: "STRING", - exp.DataType.Type.UINT128: "STRING", - exp.DataType.Type.JSONB: "JSON", - exp.DataType.Type.LONGTEXT: "STRING", - exp.DataType.Type.MONEY: "DECIMAL", - } + CAST_MAPPING = {} TYPE_MAPPING = { **MySQL.Generator.TYPE_MAPPING, From 422b8050d3e5e36b8894c71de0c76eead824ca22 Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Mon, 7 Aug 2023 18:51:34 +0800 Subject: [PATCH 05/12] fix doris dialect --- sqlglot/dialects/doris.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index dd1adc0559..f61a4f5cf6 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -120,7 +120,6 @@ class Parser(MySQL.Parser): "DATE_TRUNC": lambda args: exp.TimestampTrunc( this=seq_get(args, 1), unit=seq_get(args, 0) ), - "SYSDATE": TokenType.CURRENT_TIMESTAMP, } class Generator(MySQL.Generator): From 6cd2b359937ac8c791f482e1a769b2686abf288e Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Mon, 7 Aug 2023 19:23:09 +0800 Subject: [PATCH 06/12] fix doris dialect --- sqlglot/dialects/doris.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index f61a4f5cf6..ae8529310b 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -1,6 +1,6 @@ from __future__ import annotations import typing as t -from sqlglot import exp, generator, parser, tokens, transforms +from sqlglot import exp, generator from sqlglot.dialects.dialect import ( approx_count_distinct_sql, arrow_json_extract_sql, @@ -8,7 +8,7 @@ ) from sqlglot.dialects.mysql import MySQL from sqlglot.helper import seq_get -from sqlglot.tokens import TokenType + # (FuncType, Multiplier) DATE_DELTA_INTERVAL = { From f1caad05ec377280f36e4e713a422ce9375f2986 Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Mon, 7 Aug 2023 20:12:12 +0800 Subject: [PATCH 07/12] fix doris dialect --- sqlglot/dialects/__init__.py | 2 +- sqlglot/dialects/doris.py | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/sqlglot/dialects/__init__.py b/sqlglot/dialects/__init__.py index 1e96c1b329..821266946b 100644 --- a/sqlglot/dialects/__init__.py +++ b/sqlglot/dialects/__init__.py @@ -60,6 +60,7 @@ class Generator(Generator): from sqlglot.dialects.clickhouse import ClickHouse from sqlglot.dialects.databricks import Databricks from sqlglot.dialects.dialect import Dialect, Dialects +from sqlglot.dialects.doris import Doris from sqlglot.dialects.drill import Drill from sqlglot.dialects.duckdb import DuckDB from sqlglot.dialects.hive import Hive @@ -77,4 +78,3 @@ class Generator(Generator): from sqlglot.dialects.teradata import Teradata from sqlglot.dialects.trino import Trino from sqlglot.dialects.tsql import TSQL -from sqlglot.dialects.doris import Doris diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index ae8529310b..b02cef5155 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -1,5 +1,7 @@ from __future__ import annotations + import typing as t + from sqlglot import exp, generator from sqlglot.dialects.dialect import ( approx_count_distinct_sql, @@ -9,7 +11,6 @@ from sqlglot.dialects.mysql import MySQL from sqlglot.helper import seq_get - # (FuncType, Multiplier) DATE_DELTA_INTERVAL = { "YEAR": ("ADD_MONTHS", 12), @@ -19,6 +20,7 @@ "DAY": ("DATE_ADD", 1), } + # TRANSFORMS.pop(exp.DateTrunc) def _add_date_sql(self: generator.Generator, expression: exp.DateAdd | exp.DateSub) -> str: unit = expression.text("unit").upper() @@ -38,13 +40,15 @@ def _add_date_sql(self: generator.Generator, expression: exp.DateAdd | exp.DateS return self.func(func, expression.this, modified_increment) + def _to_date_sql(self: generator.Generator, expression: exp.TsOrDsToDate) -> str: this = self.sql(expression, "this") - time_format = self.format_time(expression) + self.format_time(expression) # if time_format and time_format not in (Doris.TIME_FORMAT, Doris.DATE_FORMAT): # return f"TO_DATE({this}, {time_format})" return f"TO_DATE({this})" + def _str_to_date_sql(self: generator.Generator, expression: exp.StrToDate) -> str: this = self.sql(expression, "this") time_format = self.format_time(expression) @@ -60,9 +64,11 @@ def _str_to_time_sql(self: generator.Generator, expression: exp.StrToTime) -> st this = f"FROM_UNIXTIME(UNIX_TIMESTAMP({this}, {time_format}))" return f"CAST({this} AS TIMESTAMP)" + def _str_to_unix_sql(self: generator.Generator, expression: exp.StrToUnix) -> str: return self.func("UNIX_TIMESTAMP", expression.this, _time_format(self, expression)) + def _time_format( self: generator.Generator, expression: exp.UnixToStr | exp.StrToUnix ) -> t.Optional[str]: @@ -71,9 +77,8 @@ def _time_format( return None return time_format -def var_map_sql( - self, expression: exp.Map | exp.VarMap, map_func_name: str = "ARRAY_MAP" -) -> str: + +def var_map_sql(self, expression: exp.Map | exp.VarMap, map_func_name: str = "ARRAY_MAP") -> str: keys = expression.args["keys"] values = expression.args["values"] @@ -86,10 +91,10 @@ def var_map_sql( args.append(self.sql(key)) args.append(self.sql(value)) - return self.func(*args,map_func_name) + return self.func(*args, map_func_name) -class Doris(MySQL): +class Doris(MySQL): DATE_FORMAT = "'yyyy-MM-dd'" DATEINT_FORMAT = "'yyyyMMdd'" TIME_FORMAT = "'yyyy-MM-dd HH:mm:ss'" @@ -102,7 +107,6 @@ class Doris(MySQL): "%e": "%-d", "%h": "%I", "%i": "%M", - "%s": "%S", "%S": "%S", "%u": "%W", "%k": "%-H", @@ -114,6 +118,7 @@ class Doris(MySQL): "%s": "%%-S", "%": "%%", } + class Parser(MySQL.Parser): FUNCTIONS = { **MySQL.Parser.FUNCTIONS, @@ -156,7 +161,7 @@ class Generator(MySQL.Generator): exp.UnixToTime: rename_func("FROM_UNIXTIME"), exp.ArrayAgg: rename_func("COLLECT_LIST"), exp.SetAgg: rename_func("COLLECT_SET"), - exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", # Only for day level + exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", # Only for day level exp.TsOrDsToDate: _to_date_sql, exp.StrToDate: _str_to_date_sql, exp.StrToTime: _str_to_time_sql, @@ -167,9 +172,5 @@ class Generator(MySQL.Generator): exp.Quantile: rename_func("PERCENTILE"), exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), # exp.StrToUnix: _str_to_unix_sql, - } # TRANSFORMS.pop(exp.Map) - - - From ea1aba2c48dbba4fb1a597a1f724e682bd6b0d21 Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Tue, 8 Aug 2023 17:35:42 +0800 Subject: [PATCH 08/12] Add test cases and api documentation for doris --- docs/sqlglot/dialects/dialect.html | 19 +- docs/sqlglot/dialects/doris.html | 1617 ++++++++++++++++++++++++++++ sqlglot/dialects/doris.py | 91 +- tests/dialects/test_dialect.py | 34 + 4 files changed, 1682 insertions(+), 79 deletions(-) create mode 100644 docs/sqlglot/dialects/doris.html diff --git a/docs/sqlglot/dialects/dialect.html b/docs/sqlglot/dialects/dialect.html index 26fd42cfa3..bb06cd2a78 100644 --- a/docs/sqlglot/dialects/dialect.html +++ b/docs/sqlglot/dialects/dialect.html @@ -96,6 +96,9 @@

API Documentation

  • TSQL
  • +
  • + DORIS +
  • @@ -436,7 +439,7 @@

    39 TERADATA = "teradata" 40 TRINO = "trino" 41 TSQL = "tsql" - 42 + 42 DORIS = "doris" 43 44class _Dialect(type): 45 classes: t.Dict[str, t.Type[Dialect]] = {} @@ -1121,6 +1124,7 @@

    40 TERADATA = "teradata" 41 TRINO = "trino" 42 TSQL = "tsql" +43 DORIS = "doris" @@ -1380,6 +1384,19 @@

    +
    +
    + DORIS = +<Dialects.DORIS: 'doris'> + + +
    + + + + +
    +
    Inherited Members
    diff --git a/docs/sqlglot/dialects/doris.html b/docs/sqlglot/dialects/doris.html new file mode 100644 index 0000000000..94e103778b --- /dev/null +++ b/docs/sqlglot/dialects/doris.html @@ -0,0 +1,1617 @@ + + + + + + + sqlglot.dialects.doris API documentation + + + + + + + + + +
    +
    + Edit on GitHub +

    +sqlglot.dialects.doris

    + + + + + + +
     1from __future__ import annotations
    + 2
    + 3from sqlglot import exp
    + 4from sqlglot.dialects.dialect import (
    + 5    approx_count_distinct_sql,
    + 6    arrow_json_extract_sql,
    + 7    rename_func,
    + 8)
    + 9from sqlglot.dialects.mysql import MySQL
    +10from sqlglot.helper import seq_get
    +11
    +12
    +13class Doris(MySQL):
    +14    class Parser(MySQL.Parser):
    +15        FUNCTIONS = {
    +16            **MySQL.Parser.FUNCTIONS,
    +17            "DATE_TRUNC": lambda args: exp.TimestampTrunc(
    +18                this=seq_get(args, 1), unit=seq_get(args, 0)
    +19            ),
    +20        }
    +21
    +22    class Generator(MySQL.Generator):
    +23        CAST_MAPPING = {}
    +24
    +25        TYPE_MAPPING = {
    +26            **MySQL.Generator.TYPE_MAPPING,
    +27            exp.DataType.Type.TEXT: "STRING",
    +28            exp.DataType.Type.TIMESTAMP: "DATETIME",
    +29            exp.DataType.Type.TIMESTAMPTZ: "DATETIME",
    +30        }
    +31
    +32        TRANSFORMS = {
    +33            **MySQL.Generator.TRANSFORMS,
    +34            exp.ApproxDistinct: approx_count_distinct_sql,
    +35            exp.JSONExtractScalar: arrow_json_extract_sql,
    +36            exp.JSONExtract: arrow_json_extract_sql,
    +37            exp.DateDiff: rename_func("DATEDIFF"),
    +38            exp.RegexpLike: rename_func("REGEXP"),
    +39            exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    +40            exp.TimestampTrunc: lambda self, e: self.func(
    +41                "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this
    +42            ),
    +43            exp.TimeStrToDate: rename_func("TO_DATE"),
    +44            exp.UnixToStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}, {self.format_time(e)})",
    +45            exp.UnixToTime: rename_func("FROM_UNIXTIME"),
    +46        }
    +47
    +48        TRANSFORMS.pop(exp.DateTrunc)
    +
    + + +
    +
    + +
    + + class + Doris(sqlglot.dialects.mysql.MySQL): + + + +
    + +
    14class Doris(MySQL):
    +15    class Parser(MySQL.Parser):
    +16        FUNCTIONS = {
    +17            **MySQL.Parser.FUNCTIONS,
    +18            "DATE_TRUNC": lambda args: exp.TimestampTrunc(
    +19                this=seq_get(args, 1), unit=seq_get(args, 0)
    +20            ),
    +21        }
    +22
    +23    class Generator(MySQL.Generator):
    +24        CAST_MAPPING = {}
    +25
    +26        TYPE_MAPPING = {
    +27            **MySQL.Generator.TYPE_MAPPING,
    +28            exp.DataType.Type.TEXT: "STRING",
    +29            exp.DataType.Type.TIMESTAMP: "DATETIME",
    +30            exp.DataType.Type.TIMESTAMPTZ: "DATETIME",
    +31        }
    +32
    +33        TRANSFORMS = {
    +34            **MySQL.Generator.TRANSFORMS,
    +35            exp.ApproxDistinct: approx_count_distinct_sql,
    +36            exp.JSONExtractScalar: arrow_json_extract_sql,
    +37            exp.JSONExtract: arrow_json_extract_sql,
    +38            exp.DateDiff: rename_func("DATEDIFF"),
    +39            exp.RegexpLike: rename_func("REGEXP"),
    +40            exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    +41            exp.TimestampTrunc: lambda self, e: self.func(
    +42                "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this
    +43            ),
    +44            exp.TimeStrToDate: rename_func("TO_DATE"),
    +45            exp.UnixToStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}, {self.format_time(e)})",
    +46            exp.UnixToTime: rename_func("FROM_UNIXTIME"),
    +47        }
    +48
    +49        TRANSFORMS.pop(exp.DateTrunc)
    +
    + + + + +
    +
    + tokenizer_class = +<class 'sqlglot.dialects.mysql.MySQL.Tokenizer'> + + +
    + + + + +
    +
    +
    + parser_class = +<class 'sqlglot.dialects.doris.Doris.Parser'> + + +
    + + + + +
    +
    +
    + generator_class = +<class 'sqlglot.dialects.doris.Doris.Generator'> + + +
    + + + + +
    +
    +
    + TIME_TRIE: Dict = + + {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}} + + +
    + + + + +
    +
    +
    + FORMAT_TRIE: Dict = + + {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}} + + +
    + + + + +
    +
    +
    + INVERSE_TIME_MAPPING: Dict[str, str] = + + {'%B': '%M', '%-m': '%c', '%-d': '%e', '%I': '%h', '%M': '%i', '%S': '%S', '%W': '%u', '%-H': '%k', '%-I': '%l', '%H:%M:%S': '%T', '%a': '%W'} + + +
    + + + + +
    +
    +
    + INVERSE_TIME_TRIE: Dict = + + {'%': {'B': {0: True}, '-': {'m': {0: True}, 'd': {0: True}, 'H': {0: True}, 'I': {0: True}}, 'I': {0: True}, 'M': {0: True}, 'S': {0: True}, 'W': {0: True}, 'H': {':': {'%': {'M': {':': {'%': {'S': {0: True}}}}}}}, 'a': {0: True}}} + + +
    + + + + +
    +
    +
    + QUOTE_START = +"'" + + +
    + + + + +
    +
    +
    + QUOTE_END = +"'" + + +
    + + + + +
    +
    +
    + IDENTIFIER_START = +'`' + + +
    + + + + +
    +
    +
    + IDENTIFIER_END = +'`' + + +
    + + + + +
    +
    +
    + BIT_START = +"b'" + + +
    + + + + +
    +
    +
    + BIT_END = +"'" + + +
    + + + + +
    +
    +
    + HEX_START = +"x'" + + +
    + + + + +
    +
    +
    + HEX_END = +"'" + + +
    + + + + +
    +
    +
    + BYTE_START = +None + + +
    + + + + +
    +
    +
    + BYTE_END = +None + + +
    + + + + +
    + +
    +
    + +
    + + class + Doris.Parser(sqlglot.dialects.mysql.MySQL.Parser): + + + +
    + +
    15    class Parser(MySQL.Parser):
    +16        FUNCTIONS = {
    +17            **MySQL.Parser.FUNCTIONS,
    +18            "DATE_TRUNC": lambda args: exp.TimestampTrunc(
    +19                this=seq_get(args, 1), unit=seq_get(args, 0)
    +20            ),
    +21        }
    +
    + + +

    Parser consumes a list of tokens produced by the Tokenizer and produces a parsed syntax tree.

    + +
    Arguments:
    + +
      +
    • error_level: The desired error level. +Default: ErrorLevel.IMMEDIATE
    • +
    • error_message_context: Determines the amount of context to capture from a +query string when displaying the error message (in number of characters). +Default: 100
    • +
    • max_errors: Maximum number of error messages to include in a raised ParseError. +This is only relevant if error_level is ErrorLevel.RAISE. +Default: 3
    • +
    +
    + + +
    +
    + FUNCTIONS = + + {'ABS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Abs'>>, 'ANY_VALUE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.AnyValue'>>, 'APPROX_DISTINCT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ApproxDistinct'>>, 'APPROX_COUNT_DISTINCT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ApproxDistinct'>>, 'APPROX_QUANTILE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ApproxQuantile'>>, 'ARRAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Array'>>, 'ARRAY_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayAgg'>>, 'ARRAY_ALL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayAll'>>, 'ARRAY_ANY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayAny'>>, 'ARRAY_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayConcat'>>, 'ARRAY_CONTAINS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayContains'>>, 'FILTER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayFilter'>>, 'ARRAY_FILTER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayFilter'>>, 'ARRAY_JOIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayJoin'>>, 'ARRAY_SIZE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArraySize'>>, 'ARRAY_SORT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArraySort'>>, 'ARRAY_SUM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArraySum'>>, 'ARRAY_UNION_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayUnionAgg'>>, 'AVG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Avg'>>, 'CASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Case'>>, 'CAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Cast'>>, 'CAST_TO_STR_TYPE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CastToStrType'>>, 'CEIL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ceil'>>, 'CEILING': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ceil'>>, 'COALESCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Coalesce'>>, 'IFNULL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Coalesce'>>, 'NVL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Coalesce'>>, 'CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Concat'>>, 'CONCAT_WS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ConcatWs'>>, 'COUNT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Count'>>, 'COUNT_IF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CountIf'>>, 'CURRENT_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentDate'>>, 'CURRENT_DATETIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentDatetime'>>, 'CURRENT_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentTime'>>, 'CURRENT_TIMESTAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentTimestamp'>>, 'CURRENT_USER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentUser'>>, 'DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Date'>>, 'DATE_ADD': <function parse_date_delta_with_interval.<locals>.func>, 'DATEDIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateDiff'>>, 'DATE_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateDiff'>>, 'DATEFROMPARTS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateFromParts'>>, 'DATE_STR_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateStrToDate'>>, 'DATE_SUB': <function parse_date_delta_with_interval.<locals>.func>, 'DATE_TO_DATE_STR': <function Parser.<lambda>>, 'DATE_TO_DI': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateToDi'>>, 'DATE_TRUNC': <function Doris.Parser.<lambda>>, 'DATETIME_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeAdd'>>, 'DATETIME_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeDiff'>>, 'DATETIME_SUB': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeSub'>>, 'DATETIME_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeTrunc'>>, 'DAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Day'>>, 'DAY_OF_MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfMonth'>>, 'DAYOFMONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfMonth'>>, 'DAY_OF_WEEK': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfWeek'>>, 'DAYOFWEEK': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfWeek'>>, 'DAY_OF_YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfYear'>>, 'DAYOFYEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfYear'>>, 'DECODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Decode'>>, 'DI_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DiToDate'>>, 'ENCODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Encode'>>, 'EXP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Exp'>>, 'EXPLODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Explode'>>, 'EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Extract'>>, 'FLOOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Floor'>>, 'FROM_BASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.FromBase'>>, 'FROM_BASE64': <bound method Func.from_arg_list of <class 'sqlglot.expressions.FromBase64'>>, 'GENERATE_SERIES': <bound method Func.from_arg_list of <class 'sqlglot.expressions.GenerateSeries'>>, 'GREATEST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Greatest'>>, 'GROUP_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.GroupConcat'>>, 'HEX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Hex'>>, 'HLL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Hll'>>, 'IF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.If'>>, 'INITCAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Initcap'>>, 'IS_NAN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.IsNan'>>, 'ISNAN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.IsNan'>>, 'JSON_ARRAY_CONTAINS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONArrayContains'>>, 'JSONB_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONBExtract'>>, 'JSONB_EXTRACT_SCALAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONBExtractScalar'>>, 'JSON_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONExtract'>>, 'JSON_EXTRACT_SCALAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONExtractScalar'>>, 'JSON_FORMAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONFormat'>>, 'J_S_O_N_OBJECT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONObject'>>, 'LAST_DATE_OF_MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LastDateOfMonth'>>, 'LEAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Least'>>, 'LEFT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Left'>>, 'LENGTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Length'>>, 'LEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Length'>>, 'LEVENSHTEIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Levenshtein'>>, 'LN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ln'>>, 'LOG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log'>>, 'LOG10': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log10'>>, 'LOG2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log2'>>, 'LOGICAL_AND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'BOOL_AND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'BOOLAND_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'LOGICAL_OR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'BOOL_OR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'BOOLOR_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'LOWER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Lower'>>, 'LCASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Lower'>>, 'MD5': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MD5'>>, 'MD5_DIGEST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MD5Digest'>>, 'MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Map'>>, 'MAP_FROM_ENTRIES': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MapFromEntries'>>, 'MATCH_AGAINST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MatchAgainst'>>, 'MAX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Max'>>, 'MIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Min'>>, 'MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Month'>>, 'MONTHS_BETWEEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MonthsBetween'>>, 'NEXT_VALUE_FOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.NextValueFor'>>, 'NUMBER_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.NumberToStr'>>, 'NVL2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Nvl2'>>, 'OPEN_J_S_O_N': <bound method Func.from_arg_list of <class 'sqlglot.expressions.OpenJSON'>>, 'PARAMETERIZED_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ParameterizedAgg'>>, 'PERCENTILE_CONT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.PercentileCont'>>, 'PERCENTILE_DISC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.PercentileDisc'>>, 'POSEXPLODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Posexplode'>>, 'POWER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Pow'>>, 'POW': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Pow'>>, 'QUANTILE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Quantile'>>, 'RANGE_N': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RangeN'>>, 'READ_CSV': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ReadCSV'>>, 'REDUCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Reduce'>>, 'REGEXP_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpExtract'>>, 'REGEXP_I_LIKE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpILike'>>, 'REGEXP_LIKE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpLike'>>, 'REGEXP_REPLACE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpReplace'>>, 'REGEXP_SPLIT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpSplit'>>, 'REPEAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Repeat'>>, 'RIGHT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Right'>>, 'ROUND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Round'>>, 'ROW_NUMBER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RowNumber'>>, 'SHA': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA'>>, 'SHA1': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA'>>, 'SHA2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA2'>>, 'SAFE_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SafeConcat'>>, 'SAFE_DIVIDE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SafeDivide'>>, 'SET_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SetAgg'>>, 'SORT_ARRAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SortArray'>>, 'SPLIT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Split'>>, 'SQRT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Sqrt'>>, 'STANDARD_HASH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StandardHash'>>, 'STAR_MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StarMap'>>, 'STARTS_WITH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StartsWith'>>, 'STARTSWITH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StartsWith'>>, 'STDDEV': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Stddev'>>, 'STDDEV_POP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StddevPop'>>, 'STDDEV_SAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StddevSamp'>>, 'STR_POSITION': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrPosition'>>, 'STR_TO_DATE': <function _str_to_date>, 'STR_TO_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrToTime'>>, 'STR_TO_UNIX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrToUnix'>>, 'STRUCT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Struct'>>, 'STRUCT_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StructExtract'>>, 'SUBSTRING': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Substring'>>, 'SUM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Sum'>>, 'TIME_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeAdd'>>, 'TIME_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeDiff'>>, 'TIME_STR_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeStrToDate'>>, 'TIME_STR_TO_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeStrToTime'>>, 'TIME_STR_TO_UNIX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeStrToUnix'>>, 'TIME_SUB': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeSub'>>, 'TIME_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeToStr'>>, 'TIME_TO_TIME_STR': <function Parser.<lambda>>, 'TIME_TO_UNIX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeToUnix'>>, 'TIME_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeTrunc'>>, 'TIMESTAMP_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampAdd'>>, 'TIMESTAMP_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampDiff'>>, 'TIMESTAMP_SUB': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampSub'>>, 'TIMESTAMP_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampTrunc'>>, 'TO_BASE64': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ToBase64'>>, 'TO_CHAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ToChar'>>, 'TRANSFORM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Transform'>>, 'TRIM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Trim'>>, 'TRY_CAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TryCast'>>, 'TS_OR_DI_TO_DI': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TsOrDiToDi'>>, 'TS_OR_DS_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TsOrDsAdd'>>, 'TS_OR_DS_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TsOrDsToDate'>>, 'TS_OR_DS_TO_DATE_STR': <function Parser.<lambda>>, 'UNHEX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Unhex'>>, 'UNIX_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.UnixToStr'>>, 'UNIX_TO_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.UnixToTime'>>, 'UNIX_TO_TIME_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.UnixToTimeStr'>>, 'UPPER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Upper'>>, 'UCASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Upper'>>, 'VAR_MAP': <function parse_var_map>, 'VARIANCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Variance'>>, 'VARIANCE_SAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Variance'>>, 'VAR_SAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Variance'>>, 'VARIANCE_POP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.VariancePop'>>, 'VAR_POP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.VariancePop'>>, 'WEEK': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Week'>>, 'WEEK_OF_YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.WeekOfYear'>>, 'WEEKOFYEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.WeekOfYear'>>, 'WHEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.When'>>, 'X_M_L_TABLE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.XMLTable'>>, 'XOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Xor'>>, 'YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Year'>>, 'GLOB': <function Parser.<lambda>>, 'LIKE': <function parse_like>, 'DATE_FORMAT': <function format_time_lambda.<locals>._format_time>, 'INSTR': <function MySQL.Parser.<lambda>>, 'LOCATE': <function locate_to_strposition>} + + +
    + + + + +
    +
    +
    + SHOW_TRIE: Dict = + + {'BINARY': {'LOGS': {0: True}}, 'MASTER': {'LOGS': {0: True}, 'STATUS': {0: True}}, 'BINLOG': {'EVENTS': {0: True}}, 'CHARACTER': {'SET': {0: True}}, 'CHARSET': {0: True}, 'COLLATION': {0: True}, 'FULL': {'COLUMNS': {0: True}, 'PROCESSLIST': {0: True}, 'TABLES': {0: True}}, 'COLUMNS': {0: True}, 'CREATE': {'DATABASE': {0: True}, 'EVENT': {0: True}, 'FUNCTION': {0: True}, 'PROCEDURE': {0: True}, 'TABLE': {0: True}, 'TRIGGER': {0: True}, 'VIEW': {0: True}}, 'DATABASES': {0: True}, 'ENGINE': {0: True}, 'STORAGE': {'ENGINES': {0: True}}, 'ENGINES': {0: True}, 'ERRORS': {0: True}, 'EVENTS': {0: True}, 'FUNCTION': {'CODE': {0: True}, 'STATUS': {0: True}}, 'GRANTS': {0: True}, 'INDEX': {0: True}, 'OPEN': {'TABLES': {0: True}}, 'PLUGINS': {0: True}, 'PROCEDURE': {'CODE': {0: True}, 'STATUS': {0: True}}, 'PRIVILEGES': {0: True}, 'PROCESSLIST': {0: True}, 'PROFILE': {0: True}, 'PROFILES': {0: True}, 'RELAYLOG': {'EVENTS': {0: True}}, 'REPLICAS': {0: True}, 'SLAVE': {'HOSTS': {0: True}, 'STATUS': {0: True}}, 'REPLICA': {'STATUS': {0: True}}, 'GLOBAL': {'STATUS': {0: True}, 'VARIABLES': {0: True}}, 'SESSION': {'STATUS': {0: True}, 'VARIABLES': {0: True}}, 'STATUS': {0: True}, 'TABLE': {'STATUS': {0: True}}, 'TABLES': {0: True}, 'TRIGGERS': {0: True}, 'VARIABLES': {0: True}, 'WARNINGS': {0: True}} + + +
    + + + + +
    +
    +
    + SET_TRIE: Dict = + + {'GLOBAL': {0: True}, 'LOCAL': {0: True}, 'SESSION': {0: True}, 'TRANSACTION': {0: True}, 'PERSIST': {0: True}, 'PERSIST_ONLY': {0: True}, 'CHARACTER': {'SET': {0: True}}, 'CHARSET': {0: True}, 'NAMES': {0: True}} + + +
    + + + + +
    +
    +
    + FORMAT_TRIE: Dict = + + {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}} + + +
    + + + + +
    +
    +
    + TIME_TRIE: Dict = + + {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}} + + +
    + + + + +
    +
    +
    Inherited Members
    +
    +
    sqlglot.parser.Parser
    +
    Parser
    +
    NO_PAREN_FUNCTIONS
    +
    NESTED_TYPE_TOKENS
    +
    SUBQUERY_PREDICATES
    +
    RESERVED_KEYWORDS
    +
    DB_CREATABLES
    +
    CREATABLES
    +
    ID_VAR_TOKENS
    +
    INTERVAL_VARS
    +
    COMMENT_TABLE_ALIAS_TOKENS
    +
    UPDATE_ALIAS_TOKENS
    +
    TRIM_TYPES
    +
    EQUALITY
    +
    COMPARISON
    +
    BITWISE
    +
    TERM
    +
    FACTOR
    +
    TIMESTAMPS
    +
    SET_OPERATIONS
    +
    JOIN_METHODS
    +
    JOIN_SIDES
    +
    JOIN_KINDS
    +
    JOIN_HINTS
    +
    LAMBDAS
    +
    COLUMN_OPERATORS
    +
    EXPRESSION_PARSERS
    +
    UNARY_PARSERS
    +
    PRIMARY_PARSERS
    +
    PLACEHOLDER_PARSERS
    +
    PROPERTY_PARSERS
    +
    ALTER_PARSERS
    +
    NO_PAREN_FUNCTION_PARSERS
    +
    FUNCTIONS_WITH_ALIASED_ARGS
    +
    QUERY_MODIFIER_PARSERS
    +
    TYPE_LITERAL_PARSERS
    +
    MODIFIABLES
    +
    DDL_SELECT_TOKENS
    +
    PRE_VOLATILE_TOKENS
    +
    TRANSACTION_KIND
    +
    TRANSACTION_CHARACTERISTICS
    +
    INSERT_ALTERNATIVES
    +
    CLONE_KINDS
    +
    TABLE_INDEX_HINT_TOKENS
    +
    WINDOW_ALIAS_TOKENS
    +
    WINDOW_BEFORE_PAREN_TOKENS
    +
    WINDOW_SIDES
    +
    ADD_CONSTRAINT_TOKENS
    +
    STRICT_CAST
    +
    CONCAT_NULL_OUTPUTS_STRING
    +
    PREFIXED_PIVOT_COLUMNS
    +
    IDENTIFY_PIVOT_STRINGS
    +
    LOG_BASE_FIRST
    +
    INDEX_OFFSET
    +
    UNNEST_COLUMN_ONLY
    +
    ALIAS_POST_TABLESAMPLE
    +
    STRICT_STRING_CONCAT
    +
    NORMALIZE_FUNCTIONS
    +
    NULL_ORDERING
    +
    FORMAT_MAPPING
    +
    error_level
    +
    error_message_context
    +
    max_errors
    +
    reset
    +
    parse
    +
    parse_into
    +
    check_errors
    +
    raise_error
    +
    expression
    +
    validate_expression
    +
    errors
    +
    sql
    + +
    + +
    +
    +
    +
    + +
    + + class + Doris.Generator(sqlglot.dialects.mysql.MySQL.Generator): + + + +
    + +
    23    class Generator(MySQL.Generator):
    +24        CAST_MAPPING = {}
    +25
    +26        TYPE_MAPPING = {
    +27            **MySQL.Generator.TYPE_MAPPING,
    +28            exp.DataType.Type.TEXT: "STRING",
    +29            exp.DataType.Type.TIMESTAMP: "DATETIME",
    +30            exp.DataType.Type.TIMESTAMPTZ: "DATETIME",
    +31        }
    +32
    +33        TRANSFORMS = {
    +34            **MySQL.Generator.TRANSFORMS,
    +35            exp.ApproxDistinct: approx_count_distinct_sql,
    +36            exp.JSONExtractScalar: arrow_json_extract_sql,
    +37            exp.JSONExtract: arrow_json_extract_sql,
    +38            exp.DateDiff: rename_func("DATEDIFF"),
    +39            exp.RegexpLike: rename_func("REGEXP"),
    +40            exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    +41            exp.TimestampTrunc: lambda self, e: self.func(
    +42                "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this
    +43            ),
    +44            exp.TimeStrToDate: rename_func("TO_DATE"),
    +45            exp.UnixToStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}, {self.format_time(e)})",
    +46            exp.UnixToTime: rename_func("FROM_UNIXTIME"),
    +47        }
    +48
    +49        TRANSFORMS.pop(exp.DateTrunc)
    +
    + + +

    Generator converts a given syntax tree to the corresponding SQL string.

    + +
    Arguments:
    + +
      +
    • pretty: Whether or not to format the produced SQL string. +Default: False.
    • +
    • identify: Determines when an identifier should be quoted. Possible values are: +False (default): Never quote, except in cases where it's mandatory by the dialect. +True or 'always': Always quote. +'safe': Only quote identifiers that are case insensitive.
    • +
    • normalize: Whether or not to normalize identifiers to lowercase. +Default: False.
    • +
    • pad: Determines the pad size in a formatted string. +Default: 2.
    • +
    • indent: Determines the indentation size in a formatted string. +Default: 2.
    • +
    • normalize_functions: Whether or not to normalize all function names. Possible values are: +"upper" or True (default): Convert names to uppercase. +"lower": Convert names to lowercase. +False: Disables function name normalization.
    • +
    • unsupported_level: Determines the generator's behavior when it encounters unsupported expressions. +Default ErrorLevel.WARN.
    • +
    • max_unsupported: Maximum number of unsupported messages to include in a raised UnsupportedError. +This is only relevant if unsupported_level is ErrorLevel.RAISE. +Default: 3
    • +
    • leading_comma: Determines whether or not the comma is leading or trailing in select expressions. +This is only relevant when generating in pretty mode. +Default: False
    • +
    • max_text_width: The max number of characters in a segment before creating new lines in pretty mode. +The default is on the smaller end because the length only represents a segment and not the true +line length. +Default: 80
    • +
    • comments: Whether or not to preserve comments in the output SQL code. +Default: True
    • +
    +
    + + +
    +
    + CAST_MAPPING = +{} + + +
    + + + + +
    +
    +
    + TYPE_MAPPING = + + {<Type.NCHAR: 'NCHAR'>: 'CHAR', <Type.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <Type.INET: 'INET'>: 'INET', <Type.TEXT: 'TEXT'>: 'STRING', <Type.TIMESTAMP: 'TIMESTAMP'>: 'DATETIME', <Type.TIMESTAMPTZ: 'TIMESTAMPTZ'>: 'DATETIME'} + + +
    + + + + +
    +
    +
    + TRANSFORMS = + + {<class 'sqlglot.expressions.DateAdd'>: <function _date_add_sql.<locals>.func>, <class 'sqlglot.expressions.TsOrDsAdd'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CaseSpecificColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CharacterSetColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CharacterSetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CheckColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CollateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CopyGrantsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CommentColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.DateFormatColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.DefaultColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.EncodeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ExecuteAsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ExternalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.HeapProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.InlineLengthColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LanguageProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LocationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.MaterializedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.NoPrimaryIndexProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnCommitProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnUpdateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.PathColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ReturnsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SettingsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SqlSecurityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.StabilityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TemporaryProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ToTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TransientProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TitleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.UppercaseColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.VarMap'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.VolatileProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.WithJournalTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CurrentDate'>: <function no_paren_current_date_sql>, <class 'sqlglot.expressions.DateDiff'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.DateStrToDate'>: <function datestrtodate_sql>, <class 'sqlglot.expressions.DateSub'>: <function _date_add_sql.<locals>.func>, <class 'sqlglot.expressions.DayOfMonth'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.DayOfWeek'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.DayOfYear'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.GroupConcat'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.ILike'>: <function no_ilike_sql>, <class 'sqlglot.expressions.JSONExtractScalar'>: <function arrow_json_extract_sql>, <class 'sqlglot.expressions.Max'>: <function max_or_greatest>, <class 'sqlglot.expressions.Min'>: <function min_or_least>, <class 'sqlglot.expressions.NullSafeEQ'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.NullSafeNEQ'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.Pivot'>: <function no_pivot_sql>, <class 'sqlglot.expressions.Select'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.StrPosition'>: <function strposition_to_locate_sql>, <class 'sqlglot.expressions.StrToDate'>: <function _str_to_date_sql>, <class 'sqlglot.expressions.StrToTime'>: <function _str_to_date_sql>, <class 'sqlglot.expressions.TableSample'>: <function no_tablesample_sql>, <class 'sqlglot.expressions.TimeStrToUnix'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.TimeStrToTime'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.TimeToStr'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.Trim'>: <function _trim_sql>, <class 'sqlglot.expressions.TryCast'>: <function no_trycast_sql>, <class 'sqlglot.expressions.WeekOfYear'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.ApproxDistinct'>: <function approx_count_distinct_sql>, <class 'sqlglot.expressions.JSONExtract'>: <function arrow_json_extract_sql>, <class 'sqlglot.expressions.RegexpLike'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.StrToUnix'>: <function Doris.Generator.<lambda>>, <class 'sqlglot.expressions.TimestampTrunc'>: <function Doris.Generator.<lambda>>, <class 'sqlglot.expressions.TimeStrToDate'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.UnixToStr'>: <function Doris.Generator.<lambda>>, <class 'sqlglot.expressions.UnixToTime'>: <function rename_func.<locals>.<lambda>>} + + +
    + + + + +
    +
    +
    + SELECT_KINDS: Tuple[str, ...] = +() + + +
    + + + + +
    +
    +
    + INVERSE_TIME_MAPPING: Dict[str, str] = + + {'%B': '%M', '%-m': '%c', '%-d': '%e', '%I': '%h', '%M': '%i', '%S': '%S', '%W': '%u', '%-H': '%k', '%-I': '%l', '%H:%M:%S': '%T', '%a': '%W'} + + +
    + + + + +
    +
    +
    + INVERSE_TIME_TRIE: Dict = + + {'%': {'B': {0: True}, '-': {'m': {0: True}, 'd': {0: True}, 'H': {0: True}, 'I': {0: True}}, 'I': {0: True}, 'M': {0: True}, 'S': {0: True}, 'W': {0: True}, 'H': {':': {'%': {'M': {':': {'%': {'S': {0: True}}}}}}}, 'a': {0: True}}} + + +
    + + + + +
    +
    + +
    +
    @classmethod
    + + def + can_identify(text: str, identify: str | bool = 'safe') -> bool: + + + +
    + +
    253    @classmethod
    +254    def can_identify(cls, text: str, identify: str | bool = "safe") -> bool:
    +255        """Checks if text can be identified given an identify option.
    +256
    +257        Args:
    +258            text: The text to check.
    +259            identify:
    +260                "always" or `True`: Always returns true.
    +261                "safe": True if the identifier is case-insensitive.
    +262
    +263        Returns:
    +264            Whether or not the given text can be identified.
    +265        """
    +266        if identify is True or identify == "always":
    +267            return True
    +268
    +269        if identify == "safe":
    +270            return not cls.case_sensitive(text)
    +271
    +272        return False
    +
    + + +

    Checks if text can be identified given an identify option.

    + +
    Arguments:
    + +
      +
    • text: The text to check.
    • +
    • identify: "always" or True: Always returns true. +"safe": True if the identifier is case-insensitive.
    • +
    + +
    Returns:
    + +
    +

    Whether or not the given text can be identified.

    +
    +
    + + +
    +
    +
    + QUOTE_START = +"'" + + +
    + + + + +
    +
    +
    + QUOTE_END = +"'" + + +
    + + + + +
    +
    +
    + IDENTIFIER_START = +'`' + + +
    + + + + +
    +
    +
    + IDENTIFIER_END = +'`' + + +
    + + + + +
    +
    +
    + STRING_ESCAPE = +"'" + + +
    + + + + +
    +
    +
    + IDENTIFIER_ESCAPE = +'"' + + +
    + + + + +
    +
    +
    + BIT_START: Optional[str] = +"b'" + + +
    + + + + +
    +
    +
    + BIT_END: Optional[str] = +"'" + + +
    + + + + +
    +
    +
    + HEX_START: Optional[str] = +"x'" + + +
    + + + + +
    +
    +
    + HEX_END: Optional[str] = +"'" + + +
    + + + + +
    +
    +
    + BYTE_START: Optional[str] = +None + + +
    + + + + +
    +
    +
    + BYTE_END: Optional[str] = +None + + +
    + + + + +
    +
    +
    Inherited Members
    +
    +
    sqlglot.generator.Generator
    +
    Generator
    +
    EXPLICIT_UNION
    +
    WRAP_DERIVED_VALUES
    +
    CREATE_FUNCTION_RETURN_AS
    +
    MATCHED_BY_SOURCE
    +
    SINGLE_STRING_INTERVAL
    +
    INTERVAL_ALLOWS_PLURAL_FORM
    +
    TABLESAMPLE_WITH_METHOD
    +
    TABLESAMPLE_SIZE_IS_PERCENT
    +
    RENAME_TABLE_WITH_DB
    +
    GROUPINGS_SEP
    +
    INDEX_ON
    +
    QUERY_HINTS
    +
    IS_BOOL_ALLOWED
    +
    LIMIT_IS_TOP
    +
    RETURNING_END
    +
    COLUMN_JOIN_MARKS_SUPPORTED
    +
    EXTRACT_ALLOWS_QUOTES
    +
    STAR_MAPPING
    +
    TIME_PART_SINGULARS
    +
    TOKEN_MAPPING
    +
    STRUCT_DELIMITER
    +
    PARAMETER_TOKEN
    +
    RESERVED_KEYWORDS
    +
    WITH_SEPARATED_COMMENTS
    +
    UNWRAPPED_INTERVAL_VALUES
    +
    SENTINEL_LINE_BREAK
    +
    INDEX_OFFSET
    +
    UNNEST_COLUMN_ONLY
    +
    ALIAS_POST_TABLESAMPLE
    +
    IDENTIFIERS_CAN_START_WITH_DIGIT
    +
    STRICT_STRING_CONCAT
    +
    NORMALIZE_FUNCTIONS
    +
    NULL_ORDERING
    +
    ESCAPE_LINE_BREAK
    +
    pretty
    +
    identify
    +
    normalize
    +
    pad
    +
    unsupported_level
    +
    max_unsupported
    +
    leading_comma
    +
    max_text_width
    +
    comments
    +
    normalize_functions
    +
    unsupported_messages
    +
    generate
    +
    unsupported
    +
    sep
    +
    seg
    +
    pad_comment
    +
    maybe_comment
    +
    wrap
    +
    no_identify
    +
    normalize_func
    +
    indent
    +
    sql
    +
    uncache_sql
    +
    cache_sql
    +
    characterset_sql
    +
    column_sql
    +
    columnposition_sql
    +
    columndef_sql
    +
    columnconstraint_sql
    +
    autoincrementcolumnconstraint_sql
    +
    compresscolumnconstraint_sql
    +
    generatedasidentitycolumnconstraint_sql
    +
    notnullcolumnconstraint_sql
    +
    primarykeycolumnconstraint_sql
    +
    uniquecolumnconstraint_sql
    +
    createable_sql
    +
    create_sql
    +
    clone_sql
    +
    describe_sql
    +
    prepend_ctes
    +
    with_sql
    +
    cte_sql
    +
    tablealias_sql
    +
    bitstring_sql
    +
    hexstring_sql
    +
    bytestring_sql
    +
    rawstring_sql
    +
    datatypesize_sql
    +
    datatype_sql
    +
    directory_sql
    +
    delete_sql
    +
    drop_sql
    +
    except_sql
    +
    except_op
    +
    fetch_sql
    +
    filter_sql
    +
    hint_sql
    +
    index_sql
    +
    identifier_sql
    +
    inputoutputformat_sql
    +
    national_sql
    +
    partition_sql
    +
    properties_sql
    +
    root_properties
    +
    properties
    +
    with_properties
    +
    locate_properties
    +
    property_sql
    +
    likeproperty_sql
    +
    fallbackproperty_sql
    +
    journalproperty_sql
    +
    freespaceproperty_sql
    +
    checksumproperty_sql
    +
    mergeblockratioproperty_sql
    +
    datablocksizeproperty_sql
    +
    blockcompressionproperty_sql
    +
    isolatedloadingproperty_sql
    +
    lockingproperty_sql
    +
    withdataproperty_sql
    +
    insert_sql
    +
    intersect_sql
    +
    intersect_op
    +
    introducer_sql
    +
    pseudotype_sql
    +
    onconflict_sql
    +
    returning_sql
    +
    rowformatdelimitedproperty_sql
    +
    withtablehint_sql
    +
    indextablehint_sql
    +
    table_sql
    +
    tablesample_sql
    +
    pivot_sql
    +
    tuple_sql
    +
    update_sql
    +
    values_sql
    +
    var_sql
    +
    into_sql
    +
    from_sql
    +
    group_sql
    +
    having_sql
    +
    join_sql
    +
    lambda_sql
    +
    lateral_sql
    +
    setitem_sql
    +
    set_sql
    +
    pragma_sql
    +
    lock_sql
    +
    literal_sql
    +
    escape_str
    +
    loaddata_sql
    +
    null_sql
    +
    boolean_sql
    +
    order_sql
    +
    cluster_sql
    +
    distribute_sql
    +
    sort_sql
    +
    ordered_sql
    +
    matchrecognize_sql
    +
    query_modifiers
    +
    offset_limit_modifiers
    +
    after_having_modifiers
    +
    after_limit_modifiers
    +
    select_sql
    +
    schema_sql
    +
    schema_columns_sql
    +
    star_sql
    +
    parameter_sql
    +
    sessionparameter_sql
    +
    placeholder_sql
    +
    subquery_sql
    +
    qualify_sql
    +
    union_sql
    +
    union_op
    +
    unnest_sql
    +
    where_sql
    +
    window_sql
    +
    partition_by_sql
    +
    windowspec_sql
    +
    withingroup_sql
    +
    between_sql
    +
    bracket_sql
    +
    safebracket_sql
    +
    all_sql
    +
    any_sql
    +
    exists_sql
    +
    case_sql
    +
    constraint_sql
    +
    nextvaluefor_sql
    +
    extract_sql
    +
    trim_sql
    +
    safeconcat_sql
    +
    check_sql
    +
    foreignkey_sql
    +
    primarykey_sql
    +
    if_sql
    +
    matchagainst_sql
    +
    jsonkeyvalue_sql
    +
    jsonobject_sql
    +
    openjsoncolumndef_sql
    +
    openjson_sql
    +
    in_sql
    +
    in_unnest_op
    +
    interval_sql
    +
    return_sql
    +
    reference_sql
    +
    anonymous_sql
    +
    paren_sql
    +
    neg_sql
    +
    not_sql
    +
    alias_sql
    +
    aliases_sql
    +
    attimezone_sql
    +
    add_sql
    +
    and_sql
    +
    connector_sql
    +
    bitwiseand_sql
    +
    bitwiseleftshift_sql
    +
    bitwisenot_sql
    +
    bitwiseor_sql
    +
    bitwiserightshift_sql
    +
    bitwisexor_sql
    +
    currentdate_sql
    +
    collate_sql
    +
    command_sql
    +
    comment_sql
    +
    mergetreettlaction_sql
    +
    mergetreettl_sql
    +
    transaction_sql
    +
    commit_sql
    +
    rollback_sql
    +
    altercolumn_sql
    +
    renametable_sql
    +
    altertable_sql
    +
    droppartition_sql
    +
    addconstraint_sql
    +
    distinct_sql
    +
    ignorenulls_sql
    +
    respectnulls_sql
    +
    intdiv_sql
    +
    dpipe_sql
    +
    safedpipe_sql
    +
    div_sql
    +
    overlaps_sql
    +
    distance_sql
    +
    dot_sql
    +
    eq_sql
    +
    escape_sql
    +
    glob_sql
    +
    gt_sql
    +
    gte_sql
    +
    ilike_sql
    +
    ilikeany_sql
    +
    is_sql
    +
    like_sql
    +
    likeany_sql
    +
    similarto_sql
    +
    lt_sql
    +
    lte_sql
    +
    mod_sql
    +
    mul_sql
    +
    neq_sql
    +
    nullsafeeq_sql
    +
    nullsafeneq_sql
    +
    or_sql
    +
    slice_sql
    +
    sub_sql
    +
    trycast_sql
    +
    use_sql
    +
    binary
    +
    function_fallback_sql
    +
    func
    +
    format_args
    +
    text_width
    +
    format_time
    +
    expressions
    +
    op_expressions
    +
    naked_property
    +
    set_operation
    +
    tag_sql
    +
    token_sql
    +
    userdefinedfunction_sql
    +
    joinhint_sql
    +
    kwarg_sql
    +
    when_sql
    +
    merge_sql
    +
    tochar_sql
    +
    dictproperty_sql
    +
    dictrange_sql
    +
    dictsubproperty_sql
    +
    oncluster_sql
    +
    clusteredbyproperty_sql
    +
    anyvalue_sql
    +
    querytransform_sql
    +
    indexconstraintoption_sql
    +
    indexcolumnconstraint_sql
    + +
    + +
    +
    +
    +
    + + \ No newline at end of file diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index b02cef5155..09e86b960a 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -11,64 +11,13 @@ from sqlglot.dialects.mysql import MySQL from sqlglot.helper import seq_get -# (FuncType, Multiplier) -DATE_DELTA_INTERVAL = { - "YEAR": ("ADD_MONTHS", 12), - "MONTH": ("ADD_MONTHS", 1), - "QUARTER": ("ADD_MONTHS", 3), - "WEEK": ("DATE_ADD", 7), - "DAY": ("DATE_ADD", 1), -} - - -# TRANSFORMS.pop(exp.DateTrunc) -def _add_date_sql(self: generator.Generator, expression: exp.DateAdd | exp.DateSub) -> str: - unit = expression.text("unit").upper() - func, multiplier = DATE_DELTA_INTERVAL.get(unit, ("DATE_ADD", 1)) - - if isinstance(expression, exp.DateSub): - multiplier *= -1 - - if expression.expression.is_number: - modified_increment = exp.Literal.number(int(expression.text("expression")) * multiplier) - else: - modified_increment = expression.expression - if multiplier != 1: - modified_increment = exp.Mul( # type: ignore - this=modified_increment, expression=exp.Literal.number(multiplier) - ) - - return self.func(func, expression.this, modified_increment) - def _to_date_sql(self: generator.Generator, expression: exp.TsOrDsToDate) -> str: this = self.sql(expression, "this") self.format_time(expression) - # if time_format and time_format not in (Doris.TIME_FORMAT, Doris.DATE_FORMAT): - # return f"TO_DATE({this}, {time_format})" return f"TO_DATE({this})" -def _str_to_date_sql(self: generator.Generator, expression: exp.StrToDate) -> str: - this = self.sql(expression, "this") - time_format = self.format_time(expression) - if time_format not in (Doris.TIME_FORMAT, Doris.DATE_FORMAT): - this = f"FROM_UNIXTIME(UNIX_TIMESTAMP({this}, {time_format}))" - return f"CAST({this} AS DATE)" - - -def _str_to_time_sql(self: generator.Generator, expression: exp.StrToTime) -> str: - this = self.sql(expression, "this") - time_format = self.format_time(expression) - if time_format not in (Doris.TIME_FORMAT, Doris.DATE_FORMAT): - this = f"FROM_UNIXTIME(UNIX_TIMESTAMP({this}, {time_format}))" - return f"CAST({this} AS TIMESTAMP)" - - -def _str_to_unix_sql(self: generator.Generator, expression: exp.StrToUnix) -> str: - return self.func("UNIX_TIMESTAMP", expression.this, _time_format(self, expression)) - - def _time_format( self: generator.Generator, expression: exp.UnixToStr | exp.StrToUnix ) -> t.Optional[str]: @@ -78,35 +27,17 @@ def _time_format( return time_format -def var_map_sql(self, expression: exp.Map | exp.VarMap, map_func_name: str = "ARRAY_MAP") -> str: - keys = expression.args["keys"] - values = expression.args["values"] - - if not isinstance(keys, exp.Array) or not isinstance(values, exp.Array): - self.unsupported("Cannot convert array columns into map.") - return self.func(map_func_name, keys, values) - - args = [] - for key, value in zip(keys.expressions, values.expressions): - args.append(self.sql(key)) - args.append(self.sql(value)) - - return self.func(*args, map_func_name) - - class Doris(MySQL): DATE_FORMAT = "'yyyy-MM-dd'" DATEINT_FORMAT = "'yyyyMMdd'" TIME_FORMAT = "'yyyy-MM-dd HH:mm:ss'" - # https://prestodb.io/docs/current/functions/datetime.html#mysql-date-functions TIME_MAPPING = { "%M": "%B", "%m": "%%-M", "%c": "%-m", "%e": "%-d", "%h": "%I", - "%i": "%M", "%S": "%S", "%u": "%W", "%k": "%-H", @@ -116,6 +47,9 @@ class Doris(MySQL): "%d": "%%-d", "%H": "%%-H", "%s": "%%-S", + "%D": "%%-j", + "%a": "%%p", + "%y": "%%Y", "%": "%%", } @@ -146,15 +80,13 @@ class Generator(MySQL.Generator): exp.RegexpLike: rename_func("REGEXP"), exp.Coalesce: rename_func("NVL"), exp.CurrentTimestamp: lambda self, e: "NOW()", - # exp.CurrentTime: lambda self, e: "NOW()", exp.TimeToStr: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", - # exp.StrToUnix: rename_func("UNIX_TIMESTAMP"), + exp.ToChar: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})", exp.TimestampTrunc: lambda self, e: self.func( "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this ), - exp.TimeStrToDate: rename_func("STR_TO_DATE"), - # exp.UnixToStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}, {self.format_time(e)})", + exp.TimeStrToDate: rename_func("TO_DATE"), exp.UnixToStr: lambda self, e: self.func( "FROM_UNIXTIME", e.this, _time_format(self, e) ), @@ -163,14 +95,17 @@ class Generator(MySQL.Generator): exp.SetAgg: rename_func("COLLECT_SET"), exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", # Only for day level exp.TsOrDsToDate: _to_date_sql, - exp.StrToDate: _str_to_date_sql, - exp.StrToTime: _str_to_time_sql, exp.Map: rename_func("ARRAY_MAP"), - exp.VarMap: var_map_sql, exp.RegexpSplit: rename_func("SPLIT_BY_STRING"), exp.Split: rename_func("SPLIT_BY_STRING"), exp.Quantile: rename_func("PERCENTILE"), exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), - # exp.StrToUnix: _str_to_unix_sql, + exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), + exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), + exp.DateTrunc: lambda self, e: self.func( + "DATE_TRUNC", e.this, "'" + e.text("unit") + "'" + ), + exp.TimestampTrunc: lambda self, e: self.func( + "DATE_TRUNC", e.this, "'" + e.text("unit") + "'" + ), } - # TRANSFORMS.pop(exp.Map) diff --git a/tests/dialects/test_dialect.py b/tests/dialects/test_dialect.py index aaaffab785..9873038f8f 100644 --- a/tests/dialects/test_dialect.py +++ b/tests/dialects/test_dialect.py @@ -90,6 +90,7 @@ def test_cast(self): "snowflake": "CAST(a AS TEXT)", "spark": "CAST(a AS STRING)", "starrocks": "CAST(a AS STRING)", + "doris": "CAST(a AS STRING)", }, ) self.validate_all( @@ -169,6 +170,7 @@ def test_cast(self): "snowflake": "CAST(a AS TEXT)", "spark": "CAST(a AS STRING)", "starrocks": "CAST(a AS STRING)", + "doris": "CAST(a AS STRING)", }, ) self.validate_all( @@ -186,6 +188,7 @@ def test_cast(self): "snowflake": "CAST(a AS VARCHAR)", "spark": "CAST(a AS STRING)", "starrocks": "CAST(a AS VARCHAR)", + "doris": "CAST(a AS VARCHAR)", }, ) self.validate_all( @@ -203,6 +206,7 @@ def test_cast(self): "snowflake": "CAST(a AS VARCHAR(3))", "spark": "CAST(a AS VARCHAR(3))", "starrocks": "CAST(a AS VARCHAR(3))", + "doris": "CAST(a AS VARCHAR(3))", }, ) self.validate_all( @@ -221,6 +225,7 @@ def test_cast(self): "spark": "CAST(a AS SMALLINT)", "sqlite": "CAST(a AS INTEGER)", "starrocks": "CAST(a AS SMALLINT)", + "doris": "CAST(a AS SMALLINT)", }, ) self.validate_all( @@ -234,6 +239,7 @@ def test_cast(self): "drill": "CAST(a AS DOUBLE)", "postgres": "CAST(a AS DOUBLE PRECISION)", "redshift": "CAST(a AS DOUBLE PRECISION)", + "doris": "CAST(a AS DOUBLE)", }, ) @@ -267,6 +273,7 @@ def test_cast(self): write={ "starrocks": "CAST(a AS DATETIME)", "redshift": "CAST(a AS TIMESTAMP)", + "doris": "CAST(a AS DATETIME)", }, ) self.validate_all( @@ -274,6 +281,7 @@ def test_cast(self): write={ "starrocks": "CAST(a AS DATETIME)", "redshift": "CAST(a AS TIMESTAMPTZ)", + "doris": "CAST(a AS DATETIME)", }, ) self.validate_all("CAST(a AS TINYINT)", write={"oracle": "CAST(a AS NUMBER)"}) @@ -408,6 +416,7 @@ def test_time(self): "hive": "UNIX_TIMESTAMP('2020-01-01', 'yyyy-mm-dd')", "presto": "TO_UNIXTIME(DATE_PARSE('2020-01-01', '%Y-%i-%d'))", "starrocks": "UNIX_TIMESTAMP('2020-01-01', '%Y-%i-%d')", + "doris": "UNIX_TIMESTAMP('2020-01-01', '%Y-%M-%d')", }, ) self.validate_all( @@ -418,6 +427,7 @@ def test_time(self): "hive": "TO_DATE('2020-01-01')", "presto": "CAST('2020-01-01' AS TIMESTAMP)", "starrocks": "TO_DATE('2020-01-01')", + "doris": "TO_DATE('2020-01-01')", }, ) self.validate_all( @@ -428,6 +438,7 @@ def test_time(self): "hive": "CAST('2020-01-01' AS TIMESTAMP)", "presto": "CAST('2020-01-01' AS TIMESTAMP)", "sqlite": "'2020-01-01'", + "doris": "CAST('2020-01-01' AS DATETIME)", }, ) self.validate_all( @@ -437,6 +448,7 @@ def test_time(self): "hive": "UNIX_TIMESTAMP('2020-01-01')", "mysql": "UNIX_TIMESTAMP('2020-01-01')", "presto": "TO_UNIXTIME(DATE_PARSE('2020-01-01', '%Y-%m-%d %T'))", + "doris": "UNIX_TIMESTAMP('2020-01-01')", }, ) self.validate_all( @@ -449,6 +461,7 @@ def test_time(self): "postgres": "TO_CHAR(x, 'YYYY-MM-DD')", "presto": "DATE_FORMAT(x, '%Y-%m-%d')", "redshift": "TO_CHAR(x, 'YYYY-MM-DD')", + "doris": "DATE_FORMAT(x, '%Y-%m-%d')", }, ) self.validate_all( @@ -459,6 +472,7 @@ def test_time(self): "hive": "CAST(x AS STRING)", "presto": "CAST(x AS VARCHAR)", "redshift": "CAST(x AS VARCHAR(MAX))", + "doris": "CAST(x AS STRING)", }, ) self.validate_all( @@ -468,6 +482,7 @@ def test_time(self): "duckdb": "EPOCH(x)", "hive": "UNIX_TIMESTAMP(x)", "presto": "TO_UNIXTIME(x)", + "doris": "UNIX_TIMESTAMP(x)", }, ) self.validate_all( @@ -476,6 +491,7 @@ def test_time(self): "duckdb": "SUBSTRING(CAST(x AS TEXT), 1, 10)", "hive": "SUBSTRING(CAST(x AS STRING), 1, 10)", "presto": "SUBSTRING(CAST(x AS VARCHAR), 1, 10)", + "doris": "SUBSTRING(CAST(x AS STRING), 1, 10)", }, ) self.validate_all( @@ -487,6 +503,7 @@ def test_time(self): "postgres": "CAST(x AS DATE)", "presto": "CAST(CAST(x AS TIMESTAMP) AS DATE)", "snowflake": "CAST(x AS DATE)", + "doris": "TO_DATE(x)", }, ) self.validate_all( @@ -505,6 +522,7 @@ def test_time(self): "hive": "FROM_UNIXTIME(x, y)", "presto": "DATE_FORMAT(FROM_UNIXTIME(x), y)", "starrocks": "FROM_UNIXTIME(x, y)", + "doris": "FROM_UNIXTIME(x, y)", }, ) self.validate_all( @@ -516,6 +534,7 @@ def test_time(self): "postgres": "TO_TIMESTAMP(x)", "presto": "FROM_UNIXTIME(x)", "starrocks": "FROM_UNIXTIME(x)", + "doris": "FROM_UNIXTIME(x)", }, ) self.validate_all( @@ -582,6 +601,7 @@ def test_time(self): "sqlite": "DATE(x, '1 DAY')", "starrocks": "DATE_ADD(x, INTERVAL 1 DAY)", "tsql": "DATEADD(DAY, 1, x)", + "doris": "DATE_ADD(x, INTERVAL 1 DAY)", }, ) self.validate_all( @@ -595,6 +615,7 @@ def test_time(self): "presto": "DATE_ADD('day', 1, x)", "spark": "DATE_ADD(x, 1)", "starrocks": "DATE_ADD(x, INTERVAL 1 DAY)", + "doris": "DATE_ADD(x, INTERVAL 1 DAY)", }, ) self.validate_all( @@ -612,6 +633,7 @@ def test_time(self): "snowflake": "DATE_TRUNC('day', x)", "starrocks": "DATE_TRUNC('day', x)", "spark": "TRUNC(x, 'day')", + "doris": "DATE_TRUNC(x, 'day')", }, ) self.validate_all( @@ -624,6 +646,7 @@ def test_time(self): "snowflake": "DATE_TRUNC('day', x)", "starrocks": "DATE_TRUNC('day', x)", "spark": "DATE_TRUNC('day', x)", + "doris": "DATE_TRUNC('day', x)", }, ) self.validate_all( @@ -684,6 +707,7 @@ def test_time(self): "snowflake": "DATE_TRUNC('year', x)", "starrocks": "DATE_TRUNC('year', x)", "spark": "TRUNC(x, 'year')", + "doris": "DATE_TRUNC(x, 'year')", }, ) self.validate_all( @@ -698,6 +722,7 @@ def test_time(self): write={ "bigquery": "TIMESTAMP_TRUNC(x, year)", "spark": "DATE_TRUNC('year', x)", + "doris": "DATE_TRUNC(x, 'year')", }, ) self.validate_all( @@ -719,6 +744,7 @@ def test_time(self): "hive": "CAST(FROM_UNIXTIME(UNIX_TIMESTAMP(x, 'yyyy-MM-ddTHH:mm:ss')) AS DATE)", "presto": "CAST(DATE_PARSE(x, '%Y-%m-%dT%T') AS DATE)", "spark": "TO_DATE(x, 'yyyy-MM-ddTHH:mm:ss')", + "doris": "STR_TO_DATE(x, '%Y-%m-%dT%H:%M:%S')", }, ) self.validate_all( @@ -730,6 +756,7 @@ def test_time(self): "hive": "CAST(x AS DATE)", "presto": "CAST(DATE_PARSE(x, '%Y-%m-%d') AS DATE)", "spark": "TO_DATE(x)", + "doris": "STR_TO_DATE(x, '%Y-%m-%d')", }, ) self.validate_all( @@ -784,6 +811,7 @@ def test_time(self): "mysql": "CAST('2022-01-01' AS TIMESTAMP)", "starrocks": "CAST('2022-01-01' AS DATETIME)", "hive": "CAST('2022-01-01' AS TIMESTAMP)", + "doris": "CAST('2022-01-01' AS DATETIME)", }, ) self.validate_all( @@ -792,6 +820,7 @@ def test_time(self): "mysql": "TIMESTAMP('2022-01-01')", "starrocks": "TIMESTAMP('2022-01-01')", "hive": "TIMESTAMP('2022-01-01')", + "doris": "TIMESTAMP('2022-01-01')", }, ) @@ -807,6 +836,7 @@ def test_time(self): "mysql", "presto", "starrocks", + "doris", ) }, write={ @@ -820,6 +850,7 @@ def test_time(self): "hive", "spark", "starrocks", + "doris", ) }, ) @@ -886,6 +917,7 @@ def test_json(self): "postgres": "x->'y'", "presto": "JSON_EXTRACT(x, 'y')", "starrocks": "x -> 'y'", + "doris": "x -> 'y'", }, write={ "mysql": "JSON_EXTRACT(x, 'y')", @@ -893,6 +925,7 @@ def test_json(self): "postgres": "x -> 'y'", "presto": "JSON_EXTRACT(x, 'y')", "starrocks": "x -> 'y'", + "doris": "x -> 'y'", }, ) self.validate_all( @@ -1115,6 +1148,7 @@ def test_operators(self): "sqlite": "LOWER(x) LIKE '%y'", "starrocks": "LOWER(x) LIKE '%y'", "trino": "LOWER(x) LIKE '%y'", + "doris": "LOWER(x) LIKE '%y'", }, ) self.validate_all( From fcd65509580f3e744077a823616b1d455516764a Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Wed, 9 Aug 2023 14:20:38 +0800 Subject: [PATCH 09/12] Clean up the code and revert any changes in the html --- docs/sqlglot/dialects/dialect.html | 14 +- docs/sqlglot/dialects/doris.html | 1617 ---------------------------- sqlglot/dialects/doris.py | 42 +- 3 files changed, 19 insertions(+), 1654 deletions(-) delete mode 100644 docs/sqlglot/dialects/doris.html diff --git a/docs/sqlglot/dialects/dialect.html b/docs/sqlglot/dialects/dialect.html index bb06cd2a78..c53e2e378e 100644 --- a/docs/sqlglot/dialects/dialect.html +++ b/docs/sqlglot/dialects/dialect.html @@ -439,7 +439,7 @@

    39 TERADATA = "teradata" 40 TRINO = "trino" 41 TSQL = "tsql" - 42 DORIS = "doris" + 42 43 44class _Dialect(type): 45 classes: t.Dict[str, t.Type[Dialect]] = {} @@ -1124,7 +1124,6 @@

    40 TERADATA = "teradata" 41 TRINO = "trino" 42 TSQL = "tsql" -43 DORIS = "doris"

    @@ -1384,19 +1383,8 @@

    -
    -
    - DORIS = -<Dialects.DORIS: 'doris'> - - -
    - - -
    -
    Inherited Members
    diff --git a/docs/sqlglot/dialects/doris.html b/docs/sqlglot/dialects/doris.html deleted file mode 100644 index 94e103778b..0000000000 --- a/docs/sqlglot/dialects/doris.html +++ /dev/null @@ -1,1617 +0,0 @@ - - - - - - - sqlglot.dialects.doris API documentation - - - - - - - - - -
    -
    - Edit on GitHub -

    -sqlglot.dialects.doris

    - - - - - - -
     1from __future__ import annotations
    - 2
    - 3from sqlglot import exp
    - 4from sqlglot.dialects.dialect import (
    - 5    approx_count_distinct_sql,
    - 6    arrow_json_extract_sql,
    - 7    rename_func,
    - 8)
    - 9from sqlglot.dialects.mysql import MySQL
    -10from sqlglot.helper import seq_get
    -11
    -12
    -13class Doris(MySQL):
    -14    class Parser(MySQL.Parser):
    -15        FUNCTIONS = {
    -16            **MySQL.Parser.FUNCTIONS,
    -17            "DATE_TRUNC": lambda args: exp.TimestampTrunc(
    -18                this=seq_get(args, 1), unit=seq_get(args, 0)
    -19            ),
    -20        }
    -21
    -22    class Generator(MySQL.Generator):
    -23        CAST_MAPPING = {}
    -24
    -25        TYPE_MAPPING = {
    -26            **MySQL.Generator.TYPE_MAPPING,
    -27            exp.DataType.Type.TEXT: "STRING",
    -28            exp.DataType.Type.TIMESTAMP: "DATETIME",
    -29            exp.DataType.Type.TIMESTAMPTZ: "DATETIME",
    -30        }
    -31
    -32        TRANSFORMS = {
    -33            **MySQL.Generator.TRANSFORMS,
    -34            exp.ApproxDistinct: approx_count_distinct_sql,
    -35            exp.JSONExtractScalar: arrow_json_extract_sql,
    -36            exp.JSONExtract: arrow_json_extract_sql,
    -37            exp.DateDiff: rename_func("DATEDIFF"),
    -38            exp.RegexpLike: rename_func("REGEXP"),
    -39            exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    -40            exp.TimestampTrunc: lambda self, e: self.func(
    -41                "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this
    -42            ),
    -43            exp.TimeStrToDate: rename_func("TO_DATE"),
    -44            exp.UnixToStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}, {self.format_time(e)})",
    -45            exp.UnixToTime: rename_func("FROM_UNIXTIME"),
    -46        }
    -47
    -48        TRANSFORMS.pop(exp.DateTrunc)
    -
    - - -
    -
    - -
    - - class - Doris(sqlglot.dialects.mysql.MySQL): - - - -
    - -
    14class Doris(MySQL):
    -15    class Parser(MySQL.Parser):
    -16        FUNCTIONS = {
    -17            **MySQL.Parser.FUNCTIONS,
    -18            "DATE_TRUNC": lambda args: exp.TimestampTrunc(
    -19                this=seq_get(args, 1), unit=seq_get(args, 0)
    -20            ),
    -21        }
    -22
    -23    class Generator(MySQL.Generator):
    -24        CAST_MAPPING = {}
    -25
    -26        TYPE_MAPPING = {
    -27            **MySQL.Generator.TYPE_MAPPING,
    -28            exp.DataType.Type.TEXT: "STRING",
    -29            exp.DataType.Type.TIMESTAMP: "DATETIME",
    -30            exp.DataType.Type.TIMESTAMPTZ: "DATETIME",
    -31        }
    -32
    -33        TRANSFORMS = {
    -34            **MySQL.Generator.TRANSFORMS,
    -35            exp.ApproxDistinct: approx_count_distinct_sql,
    -36            exp.JSONExtractScalar: arrow_json_extract_sql,
    -37            exp.JSONExtract: arrow_json_extract_sql,
    -38            exp.DateDiff: rename_func("DATEDIFF"),
    -39            exp.RegexpLike: rename_func("REGEXP"),
    -40            exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    -41            exp.TimestampTrunc: lambda self, e: self.func(
    -42                "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this
    -43            ),
    -44            exp.TimeStrToDate: rename_func("TO_DATE"),
    -45            exp.UnixToStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}, {self.format_time(e)})",
    -46            exp.UnixToTime: rename_func("FROM_UNIXTIME"),
    -47        }
    -48
    -49        TRANSFORMS.pop(exp.DateTrunc)
    -
    - - - - -
    -
    - tokenizer_class = -<class 'sqlglot.dialects.mysql.MySQL.Tokenizer'> - - -
    - - - - -
    -
    -
    - parser_class = -<class 'sqlglot.dialects.doris.Doris.Parser'> - - -
    - - - - -
    -
    -
    - generator_class = -<class 'sqlglot.dialects.doris.Doris.Generator'> - - -
    - - - - -
    -
    -
    - TIME_TRIE: Dict = - - {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}} - - -
    - - - - -
    -
    -
    - FORMAT_TRIE: Dict = - - {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}} - - -
    - - - - -
    -
    -
    - INVERSE_TIME_MAPPING: Dict[str, str] = - - {'%B': '%M', '%-m': '%c', '%-d': '%e', '%I': '%h', '%M': '%i', '%S': '%S', '%W': '%u', '%-H': '%k', '%-I': '%l', '%H:%M:%S': '%T', '%a': '%W'} - - -
    - - - - -
    -
    -
    - INVERSE_TIME_TRIE: Dict = - - {'%': {'B': {0: True}, '-': {'m': {0: True}, 'd': {0: True}, 'H': {0: True}, 'I': {0: True}}, 'I': {0: True}, 'M': {0: True}, 'S': {0: True}, 'W': {0: True}, 'H': {':': {'%': {'M': {':': {'%': {'S': {0: True}}}}}}}, 'a': {0: True}}} - - -
    - - - - -
    -
    -
    - QUOTE_START = -"'" - - -
    - - - - -
    -
    -
    - QUOTE_END = -"'" - - -
    - - - - -
    -
    -
    - IDENTIFIER_START = -'`' - - -
    - - - - -
    -
    -
    - IDENTIFIER_END = -'`' - - -
    - - - - -
    -
    -
    - BIT_START = -"b'" - - -
    - - - - -
    -
    -
    - BIT_END = -"'" - - -
    - - - - -
    -
    -
    - HEX_START = -"x'" - - -
    - - - - -
    -
    -
    - HEX_END = -"'" - - -
    - - - - -
    -
    -
    - BYTE_START = -None - - -
    - - - - -
    -
    -
    - BYTE_END = -None - - -
    - - - - -
    - -
    -
    - -
    - - class - Doris.Parser(sqlglot.dialects.mysql.MySQL.Parser): - - - -
    - -
    15    class Parser(MySQL.Parser):
    -16        FUNCTIONS = {
    -17            **MySQL.Parser.FUNCTIONS,
    -18            "DATE_TRUNC": lambda args: exp.TimestampTrunc(
    -19                this=seq_get(args, 1), unit=seq_get(args, 0)
    -20            ),
    -21        }
    -
    - - -

    Parser consumes a list of tokens produced by the Tokenizer and produces a parsed syntax tree.

    - -
    Arguments:
    - -
      -
    • error_level: The desired error level. -Default: ErrorLevel.IMMEDIATE
    • -
    • error_message_context: Determines the amount of context to capture from a -query string when displaying the error message (in number of characters). -Default: 100
    • -
    • max_errors: Maximum number of error messages to include in a raised ParseError. -This is only relevant if error_level is ErrorLevel.RAISE. -Default: 3
    • -
    -
    - - -
    -
    - FUNCTIONS = - - {'ABS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Abs'>>, 'ANY_VALUE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.AnyValue'>>, 'APPROX_DISTINCT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ApproxDistinct'>>, 'APPROX_COUNT_DISTINCT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ApproxDistinct'>>, 'APPROX_QUANTILE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ApproxQuantile'>>, 'ARRAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Array'>>, 'ARRAY_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayAgg'>>, 'ARRAY_ALL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayAll'>>, 'ARRAY_ANY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayAny'>>, 'ARRAY_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayConcat'>>, 'ARRAY_CONTAINS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayContains'>>, 'FILTER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayFilter'>>, 'ARRAY_FILTER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayFilter'>>, 'ARRAY_JOIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayJoin'>>, 'ARRAY_SIZE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArraySize'>>, 'ARRAY_SORT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArraySort'>>, 'ARRAY_SUM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArraySum'>>, 'ARRAY_UNION_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayUnionAgg'>>, 'AVG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Avg'>>, 'CASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Case'>>, 'CAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Cast'>>, 'CAST_TO_STR_TYPE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CastToStrType'>>, 'CEIL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ceil'>>, 'CEILING': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ceil'>>, 'COALESCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Coalesce'>>, 'IFNULL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Coalesce'>>, 'NVL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Coalesce'>>, 'CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Concat'>>, 'CONCAT_WS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ConcatWs'>>, 'COUNT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Count'>>, 'COUNT_IF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CountIf'>>, 'CURRENT_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentDate'>>, 'CURRENT_DATETIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentDatetime'>>, 'CURRENT_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentTime'>>, 'CURRENT_TIMESTAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentTimestamp'>>, 'CURRENT_USER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentUser'>>, 'DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Date'>>, 'DATE_ADD': <function parse_date_delta_with_interval.<locals>.func>, 'DATEDIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateDiff'>>, 'DATE_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateDiff'>>, 'DATEFROMPARTS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateFromParts'>>, 'DATE_STR_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateStrToDate'>>, 'DATE_SUB': <function parse_date_delta_with_interval.<locals>.func>, 'DATE_TO_DATE_STR': <function Parser.<lambda>>, 'DATE_TO_DI': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateToDi'>>, 'DATE_TRUNC': <function Doris.Parser.<lambda>>, 'DATETIME_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeAdd'>>, 'DATETIME_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeDiff'>>, 'DATETIME_SUB': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeSub'>>, 'DATETIME_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeTrunc'>>, 'DAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Day'>>, 'DAY_OF_MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfMonth'>>, 'DAYOFMONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfMonth'>>, 'DAY_OF_WEEK': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfWeek'>>, 'DAYOFWEEK': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfWeek'>>, 'DAY_OF_YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfYear'>>, 'DAYOFYEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfYear'>>, 'DECODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Decode'>>, 'DI_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DiToDate'>>, 'ENCODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Encode'>>, 'EXP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Exp'>>, 'EXPLODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Explode'>>, 'EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Extract'>>, 'FLOOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Floor'>>, 'FROM_BASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.FromBase'>>, 'FROM_BASE64': <bound method Func.from_arg_list of <class 'sqlglot.expressions.FromBase64'>>, 'GENERATE_SERIES': <bound method Func.from_arg_list of <class 'sqlglot.expressions.GenerateSeries'>>, 'GREATEST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Greatest'>>, 'GROUP_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.GroupConcat'>>, 'HEX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Hex'>>, 'HLL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Hll'>>, 'IF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.If'>>, 'INITCAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Initcap'>>, 'IS_NAN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.IsNan'>>, 'ISNAN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.IsNan'>>, 'JSON_ARRAY_CONTAINS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONArrayContains'>>, 'JSONB_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONBExtract'>>, 'JSONB_EXTRACT_SCALAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONBExtractScalar'>>, 'JSON_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONExtract'>>, 'JSON_EXTRACT_SCALAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONExtractScalar'>>, 'JSON_FORMAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONFormat'>>, 'J_S_O_N_OBJECT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONObject'>>, 'LAST_DATE_OF_MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LastDateOfMonth'>>, 'LEAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Least'>>, 'LEFT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Left'>>, 'LENGTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Length'>>, 'LEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Length'>>, 'LEVENSHTEIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Levenshtein'>>, 'LN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ln'>>, 'LOG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log'>>, 'LOG10': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log10'>>, 'LOG2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log2'>>, 'LOGICAL_AND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'BOOL_AND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'BOOLAND_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'LOGICAL_OR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'BOOL_OR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'BOOLOR_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'LOWER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Lower'>>, 'LCASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Lower'>>, 'MD5': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MD5'>>, 'MD5_DIGEST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MD5Digest'>>, 'MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Map'>>, 'MAP_FROM_ENTRIES': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MapFromEntries'>>, 'MATCH_AGAINST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MatchAgainst'>>, 'MAX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Max'>>, 'MIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Min'>>, 'MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Month'>>, 'MONTHS_BETWEEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MonthsBetween'>>, 'NEXT_VALUE_FOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.NextValueFor'>>, 'NUMBER_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.NumberToStr'>>, 'NVL2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Nvl2'>>, 'OPEN_J_S_O_N': <bound method Func.from_arg_list of <class 'sqlglot.expressions.OpenJSON'>>, 'PARAMETERIZED_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ParameterizedAgg'>>, 'PERCENTILE_CONT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.PercentileCont'>>, 'PERCENTILE_DISC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.PercentileDisc'>>, 'POSEXPLODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Posexplode'>>, 'POWER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Pow'>>, 'POW': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Pow'>>, 'QUANTILE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Quantile'>>, 'RANGE_N': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RangeN'>>, 'READ_CSV': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ReadCSV'>>, 'REDUCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Reduce'>>, 'REGEXP_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpExtract'>>, 'REGEXP_I_LIKE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpILike'>>, 'REGEXP_LIKE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpLike'>>, 'REGEXP_REPLACE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpReplace'>>, 'REGEXP_SPLIT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpSplit'>>, 'REPEAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Repeat'>>, 'RIGHT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Right'>>, 'ROUND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Round'>>, 'ROW_NUMBER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RowNumber'>>, 'SHA': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA'>>, 'SHA1': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA'>>, 'SHA2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA2'>>, 'SAFE_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SafeConcat'>>, 'SAFE_DIVIDE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SafeDivide'>>, 'SET_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SetAgg'>>, 'SORT_ARRAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SortArray'>>, 'SPLIT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Split'>>, 'SQRT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Sqrt'>>, 'STANDARD_HASH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StandardHash'>>, 'STAR_MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StarMap'>>, 'STARTS_WITH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StartsWith'>>, 'STARTSWITH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StartsWith'>>, 'STDDEV': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Stddev'>>, 'STDDEV_POP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StddevPop'>>, 'STDDEV_SAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StddevSamp'>>, 'STR_POSITION': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrPosition'>>, 'STR_TO_DATE': <function _str_to_date>, 'STR_TO_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrToTime'>>, 'STR_TO_UNIX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrToUnix'>>, 'STRUCT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Struct'>>, 'STRUCT_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StructExtract'>>, 'SUBSTRING': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Substring'>>, 'SUM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Sum'>>, 'TIME_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeAdd'>>, 'TIME_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeDiff'>>, 'TIME_STR_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeStrToDate'>>, 'TIME_STR_TO_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeStrToTime'>>, 'TIME_STR_TO_UNIX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeStrToUnix'>>, 'TIME_SUB': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeSub'>>, 'TIME_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeToStr'>>, 'TIME_TO_TIME_STR': <function Parser.<lambda>>, 'TIME_TO_UNIX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeToUnix'>>, 'TIME_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeTrunc'>>, 'TIMESTAMP_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampAdd'>>, 'TIMESTAMP_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampDiff'>>, 'TIMESTAMP_SUB': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampSub'>>, 'TIMESTAMP_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampTrunc'>>, 'TO_BASE64': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ToBase64'>>, 'TO_CHAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ToChar'>>, 'TRANSFORM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Transform'>>, 'TRIM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Trim'>>, 'TRY_CAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TryCast'>>, 'TS_OR_DI_TO_DI': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TsOrDiToDi'>>, 'TS_OR_DS_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TsOrDsAdd'>>, 'TS_OR_DS_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TsOrDsToDate'>>, 'TS_OR_DS_TO_DATE_STR': <function Parser.<lambda>>, 'UNHEX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Unhex'>>, 'UNIX_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.UnixToStr'>>, 'UNIX_TO_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.UnixToTime'>>, 'UNIX_TO_TIME_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.UnixToTimeStr'>>, 'UPPER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Upper'>>, 'UCASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Upper'>>, 'VAR_MAP': <function parse_var_map>, 'VARIANCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Variance'>>, 'VARIANCE_SAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Variance'>>, 'VAR_SAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Variance'>>, 'VARIANCE_POP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.VariancePop'>>, 'VAR_POP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.VariancePop'>>, 'WEEK': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Week'>>, 'WEEK_OF_YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.WeekOfYear'>>, 'WEEKOFYEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.WeekOfYear'>>, 'WHEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.When'>>, 'X_M_L_TABLE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.XMLTable'>>, 'XOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Xor'>>, 'YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Year'>>, 'GLOB': <function Parser.<lambda>>, 'LIKE': <function parse_like>, 'DATE_FORMAT': <function format_time_lambda.<locals>._format_time>, 'INSTR': <function MySQL.Parser.<lambda>>, 'LOCATE': <function locate_to_strposition>} - - -
    - - - - -
    -
    -
    - SHOW_TRIE: Dict = - - {'BINARY': {'LOGS': {0: True}}, 'MASTER': {'LOGS': {0: True}, 'STATUS': {0: True}}, 'BINLOG': {'EVENTS': {0: True}}, 'CHARACTER': {'SET': {0: True}}, 'CHARSET': {0: True}, 'COLLATION': {0: True}, 'FULL': {'COLUMNS': {0: True}, 'PROCESSLIST': {0: True}, 'TABLES': {0: True}}, 'COLUMNS': {0: True}, 'CREATE': {'DATABASE': {0: True}, 'EVENT': {0: True}, 'FUNCTION': {0: True}, 'PROCEDURE': {0: True}, 'TABLE': {0: True}, 'TRIGGER': {0: True}, 'VIEW': {0: True}}, 'DATABASES': {0: True}, 'ENGINE': {0: True}, 'STORAGE': {'ENGINES': {0: True}}, 'ENGINES': {0: True}, 'ERRORS': {0: True}, 'EVENTS': {0: True}, 'FUNCTION': {'CODE': {0: True}, 'STATUS': {0: True}}, 'GRANTS': {0: True}, 'INDEX': {0: True}, 'OPEN': {'TABLES': {0: True}}, 'PLUGINS': {0: True}, 'PROCEDURE': {'CODE': {0: True}, 'STATUS': {0: True}}, 'PRIVILEGES': {0: True}, 'PROCESSLIST': {0: True}, 'PROFILE': {0: True}, 'PROFILES': {0: True}, 'RELAYLOG': {'EVENTS': {0: True}}, 'REPLICAS': {0: True}, 'SLAVE': {'HOSTS': {0: True}, 'STATUS': {0: True}}, 'REPLICA': {'STATUS': {0: True}}, 'GLOBAL': {'STATUS': {0: True}, 'VARIABLES': {0: True}}, 'SESSION': {'STATUS': {0: True}, 'VARIABLES': {0: True}}, 'STATUS': {0: True}, 'TABLE': {'STATUS': {0: True}}, 'TABLES': {0: True}, 'TRIGGERS': {0: True}, 'VARIABLES': {0: True}, 'WARNINGS': {0: True}} - - -
    - - - - -
    -
    -
    - SET_TRIE: Dict = - - {'GLOBAL': {0: True}, 'LOCAL': {0: True}, 'SESSION': {0: True}, 'TRANSACTION': {0: True}, 'PERSIST': {0: True}, 'PERSIST_ONLY': {0: True}, 'CHARACTER': {'SET': {0: True}}, 'CHARSET': {0: True}, 'NAMES': {0: True}} - - -
    - - - - -
    -
    -
    - FORMAT_TRIE: Dict = - - {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}} - - -
    - - - - -
    -
    -
    - TIME_TRIE: Dict = - - {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}} - - -
    - - - - -
    -
    -
    Inherited Members
    -
    -
    sqlglot.parser.Parser
    -
    Parser
    -
    NO_PAREN_FUNCTIONS
    -
    NESTED_TYPE_TOKENS
    -
    SUBQUERY_PREDICATES
    -
    RESERVED_KEYWORDS
    -
    DB_CREATABLES
    -
    CREATABLES
    -
    ID_VAR_TOKENS
    -
    INTERVAL_VARS
    -
    COMMENT_TABLE_ALIAS_TOKENS
    -
    UPDATE_ALIAS_TOKENS
    -
    TRIM_TYPES
    -
    EQUALITY
    -
    COMPARISON
    -
    BITWISE
    -
    TERM
    -
    FACTOR
    -
    TIMESTAMPS
    -
    SET_OPERATIONS
    -
    JOIN_METHODS
    -
    JOIN_SIDES
    -
    JOIN_KINDS
    -
    JOIN_HINTS
    -
    LAMBDAS
    -
    COLUMN_OPERATORS
    -
    EXPRESSION_PARSERS
    -
    UNARY_PARSERS
    -
    PRIMARY_PARSERS
    -
    PLACEHOLDER_PARSERS
    -
    PROPERTY_PARSERS
    -
    ALTER_PARSERS
    -
    NO_PAREN_FUNCTION_PARSERS
    -
    FUNCTIONS_WITH_ALIASED_ARGS
    -
    QUERY_MODIFIER_PARSERS
    -
    TYPE_LITERAL_PARSERS
    -
    MODIFIABLES
    -
    DDL_SELECT_TOKENS
    -
    PRE_VOLATILE_TOKENS
    -
    TRANSACTION_KIND
    -
    TRANSACTION_CHARACTERISTICS
    -
    INSERT_ALTERNATIVES
    -
    CLONE_KINDS
    -
    TABLE_INDEX_HINT_TOKENS
    -
    WINDOW_ALIAS_TOKENS
    -
    WINDOW_BEFORE_PAREN_TOKENS
    -
    WINDOW_SIDES
    -
    ADD_CONSTRAINT_TOKENS
    -
    STRICT_CAST
    -
    CONCAT_NULL_OUTPUTS_STRING
    -
    PREFIXED_PIVOT_COLUMNS
    -
    IDENTIFY_PIVOT_STRINGS
    -
    LOG_BASE_FIRST
    -
    INDEX_OFFSET
    -
    UNNEST_COLUMN_ONLY
    -
    ALIAS_POST_TABLESAMPLE
    -
    STRICT_STRING_CONCAT
    -
    NORMALIZE_FUNCTIONS
    -
    NULL_ORDERING
    -
    FORMAT_MAPPING
    -
    error_level
    -
    error_message_context
    -
    max_errors
    -
    reset
    -
    parse
    -
    parse_into
    -
    check_errors
    -
    raise_error
    -
    expression
    -
    validate_expression
    -
    errors
    -
    sql
    - -
    - -
    -
    -
    -
    - -
    - - class - Doris.Generator(sqlglot.dialects.mysql.MySQL.Generator): - - - -
    - -
    23    class Generator(MySQL.Generator):
    -24        CAST_MAPPING = {}
    -25
    -26        TYPE_MAPPING = {
    -27            **MySQL.Generator.TYPE_MAPPING,
    -28            exp.DataType.Type.TEXT: "STRING",
    -29            exp.DataType.Type.TIMESTAMP: "DATETIME",
    -30            exp.DataType.Type.TIMESTAMPTZ: "DATETIME",
    -31        }
    -32
    -33        TRANSFORMS = {
    -34            **MySQL.Generator.TRANSFORMS,
    -35            exp.ApproxDistinct: approx_count_distinct_sql,
    -36            exp.JSONExtractScalar: arrow_json_extract_sql,
    -37            exp.JSONExtract: arrow_json_extract_sql,
    -38            exp.DateDiff: rename_func("DATEDIFF"),
    -39            exp.RegexpLike: rename_func("REGEXP"),
    -40            exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    -41            exp.TimestampTrunc: lambda self, e: self.func(
    -42                "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this
    -43            ),
    -44            exp.TimeStrToDate: rename_func("TO_DATE"),
    -45            exp.UnixToStr: lambda self, e: f"FROM_UNIXTIME({self.sql(e, 'this')}, {self.format_time(e)})",
    -46            exp.UnixToTime: rename_func("FROM_UNIXTIME"),
    -47        }
    -48
    -49        TRANSFORMS.pop(exp.DateTrunc)
    -
    - - -

    Generator converts a given syntax tree to the corresponding SQL string.

    - -
    Arguments:
    - -
      -
    • pretty: Whether or not to format the produced SQL string. -Default: False.
    • -
    • identify: Determines when an identifier should be quoted. Possible values are: -False (default): Never quote, except in cases where it's mandatory by the dialect. -True or 'always': Always quote. -'safe': Only quote identifiers that are case insensitive.
    • -
    • normalize: Whether or not to normalize identifiers to lowercase. -Default: False.
    • -
    • pad: Determines the pad size in a formatted string. -Default: 2.
    • -
    • indent: Determines the indentation size in a formatted string. -Default: 2.
    • -
    • normalize_functions: Whether or not to normalize all function names. Possible values are: -"upper" or True (default): Convert names to uppercase. -"lower": Convert names to lowercase. -False: Disables function name normalization.
    • -
    • unsupported_level: Determines the generator's behavior when it encounters unsupported expressions. -Default ErrorLevel.WARN.
    • -
    • max_unsupported: Maximum number of unsupported messages to include in a raised UnsupportedError. -This is only relevant if unsupported_level is ErrorLevel.RAISE. -Default: 3
    • -
    • leading_comma: Determines whether or not the comma is leading or trailing in select expressions. -This is only relevant when generating in pretty mode. -Default: False
    • -
    • max_text_width: The max number of characters in a segment before creating new lines in pretty mode. -The default is on the smaller end because the length only represents a segment and not the true -line length. -Default: 80
    • -
    • comments: Whether or not to preserve comments in the output SQL code. -Default: True
    • -
    -
    - - -
    -
    - CAST_MAPPING = -{} - - -
    - - - - -
    -
    -
    - TYPE_MAPPING = - - {<Type.NCHAR: 'NCHAR'>: 'CHAR', <Type.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <Type.INET: 'INET'>: 'INET', <Type.TEXT: 'TEXT'>: 'STRING', <Type.TIMESTAMP: 'TIMESTAMP'>: 'DATETIME', <Type.TIMESTAMPTZ: 'TIMESTAMPTZ'>: 'DATETIME'} - - -
    - - - - -
    -
    -
    - TRANSFORMS = - - {<class 'sqlglot.expressions.DateAdd'>: <function _date_add_sql.<locals>.func>, <class 'sqlglot.expressions.TsOrDsAdd'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CaseSpecificColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CharacterSetColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CharacterSetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CheckColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CollateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CopyGrantsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CommentColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.DateFormatColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.DefaultColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.EncodeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ExecuteAsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ExternalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.HeapProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.InlineLengthColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LanguageProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LocationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.MaterializedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.NoPrimaryIndexProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnCommitProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnUpdateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.PathColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ReturnsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SettingsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SqlSecurityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.StabilityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TemporaryProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ToTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TransientProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TitleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.UppercaseColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.VarMap'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.VolatileProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.WithJournalTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CurrentDate'>: <function no_paren_current_date_sql>, <class 'sqlglot.expressions.DateDiff'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.DateStrToDate'>: <function datestrtodate_sql>, <class 'sqlglot.expressions.DateSub'>: <function _date_add_sql.<locals>.func>, <class 'sqlglot.expressions.DayOfMonth'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.DayOfWeek'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.DayOfYear'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.GroupConcat'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.ILike'>: <function no_ilike_sql>, <class 'sqlglot.expressions.JSONExtractScalar'>: <function arrow_json_extract_sql>, <class 'sqlglot.expressions.Max'>: <function max_or_greatest>, <class 'sqlglot.expressions.Min'>: <function min_or_least>, <class 'sqlglot.expressions.NullSafeEQ'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.NullSafeNEQ'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.Pivot'>: <function no_pivot_sql>, <class 'sqlglot.expressions.Select'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.StrPosition'>: <function strposition_to_locate_sql>, <class 'sqlglot.expressions.StrToDate'>: <function _str_to_date_sql>, <class 'sqlglot.expressions.StrToTime'>: <function _str_to_date_sql>, <class 'sqlglot.expressions.TableSample'>: <function no_tablesample_sql>, <class 'sqlglot.expressions.TimeStrToUnix'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.TimeStrToTime'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.TimeToStr'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.Trim'>: <function _trim_sql>, <class 'sqlglot.expressions.TryCast'>: <function no_trycast_sql>, <class 'sqlglot.expressions.WeekOfYear'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.ApproxDistinct'>: <function approx_count_distinct_sql>, <class 'sqlglot.expressions.JSONExtract'>: <function arrow_json_extract_sql>, <class 'sqlglot.expressions.RegexpLike'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.StrToUnix'>: <function Doris.Generator.<lambda>>, <class 'sqlglot.expressions.TimestampTrunc'>: <function Doris.Generator.<lambda>>, <class 'sqlglot.expressions.TimeStrToDate'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.UnixToStr'>: <function Doris.Generator.<lambda>>, <class 'sqlglot.expressions.UnixToTime'>: <function rename_func.<locals>.<lambda>>} - - -
    - - - - -
    -
    -
    - SELECT_KINDS: Tuple[str, ...] = -() - - -
    - - - - -
    -
    -
    - INVERSE_TIME_MAPPING: Dict[str, str] = - - {'%B': '%M', '%-m': '%c', '%-d': '%e', '%I': '%h', '%M': '%i', '%S': '%S', '%W': '%u', '%-H': '%k', '%-I': '%l', '%H:%M:%S': '%T', '%a': '%W'} - - -
    - - - - -
    -
    -
    - INVERSE_TIME_TRIE: Dict = - - {'%': {'B': {0: True}, '-': {'m': {0: True}, 'd': {0: True}, 'H': {0: True}, 'I': {0: True}}, 'I': {0: True}, 'M': {0: True}, 'S': {0: True}, 'W': {0: True}, 'H': {':': {'%': {'M': {':': {'%': {'S': {0: True}}}}}}}, 'a': {0: True}}} - - -
    - - - - -
    -
    - -
    -
    @classmethod
    - - def - can_identify(text: str, identify: str | bool = 'safe') -> bool: - - - -
    - -
    253    @classmethod
    -254    def can_identify(cls, text: str, identify: str | bool = "safe") -> bool:
    -255        """Checks if text can be identified given an identify option.
    -256
    -257        Args:
    -258            text: The text to check.
    -259            identify:
    -260                "always" or `True`: Always returns true.
    -261                "safe": True if the identifier is case-insensitive.
    -262
    -263        Returns:
    -264            Whether or not the given text can be identified.
    -265        """
    -266        if identify is True or identify == "always":
    -267            return True
    -268
    -269        if identify == "safe":
    -270            return not cls.case_sensitive(text)
    -271
    -272        return False
    -
    - - -

    Checks if text can be identified given an identify option.

    - -
    Arguments:
    - -
      -
    • text: The text to check.
    • -
    • identify: "always" or True: Always returns true. -"safe": True if the identifier is case-insensitive.
    • -
    - -
    Returns:
    - -
    -

    Whether or not the given text can be identified.

    -
    -
    - - -
    -
    -
    - QUOTE_START = -"'" - - -
    - - - - -
    -
    -
    - QUOTE_END = -"'" - - -
    - - - - -
    -
    -
    - IDENTIFIER_START = -'`' - - -
    - - - - -
    -
    -
    - IDENTIFIER_END = -'`' - - -
    - - - - -
    -
    -
    - STRING_ESCAPE = -"'" - - -
    - - - - -
    -
    -
    - IDENTIFIER_ESCAPE = -'"' - - -
    - - - - -
    -
    -
    - BIT_START: Optional[str] = -"b'" - - -
    - - - - -
    -
    -
    - BIT_END: Optional[str] = -"'" - - -
    - - - - -
    -
    -
    - HEX_START: Optional[str] = -"x'" - - -
    - - - - -
    -
    -
    - HEX_END: Optional[str] = -"'" - - -
    - - - - -
    -
    -
    - BYTE_START: Optional[str] = -None - - -
    - - - - -
    -
    -
    - BYTE_END: Optional[str] = -None - - -
    - - - - -
    -
    -
    Inherited Members
    -
    -
    sqlglot.generator.Generator
    -
    Generator
    -
    EXPLICIT_UNION
    -
    WRAP_DERIVED_VALUES
    -
    CREATE_FUNCTION_RETURN_AS
    -
    MATCHED_BY_SOURCE
    -
    SINGLE_STRING_INTERVAL
    -
    INTERVAL_ALLOWS_PLURAL_FORM
    -
    TABLESAMPLE_WITH_METHOD
    -
    TABLESAMPLE_SIZE_IS_PERCENT
    -
    RENAME_TABLE_WITH_DB
    -
    GROUPINGS_SEP
    -
    INDEX_ON
    -
    QUERY_HINTS
    -
    IS_BOOL_ALLOWED
    -
    LIMIT_IS_TOP
    -
    RETURNING_END
    -
    COLUMN_JOIN_MARKS_SUPPORTED
    -
    EXTRACT_ALLOWS_QUOTES
    -
    STAR_MAPPING
    -
    TIME_PART_SINGULARS
    -
    TOKEN_MAPPING
    -
    STRUCT_DELIMITER
    -
    PARAMETER_TOKEN
    -
    RESERVED_KEYWORDS
    -
    WITH_SEPARATED_COMMENTS
    -
    UNWRAPPED_INTERVAL_VALUES
    -
    SENTINEL_LINE_BREAK
    -
    INDEX_OFFSET
    -
    UNNEST_COLUMN_ONLY
    -
    ALIAS_POST_TABLESAMPLE
    -
    IDENTIFIERS_CAN_START_WITH_DIGIT
    -
    STRICT_STRING_CONCAT
    -
    NORMALIZE_FUNCTIONS
    -
    NULL_ORDERING
    -
    ESCAPE_LINE_BREAK
    -
    pretty
    -
    identify
    -
    normalize
    -
    pad
    -
    unsupported_level
    -
    max_unsupported
    -
    leading_comma
    -
    max_text_width
    -
    comments
    -
    normalize_functions
    -
    unsupported_messages
    -
    generate
    -
    unsupported
    -
    sep
    -
    seg
    -
    pad_comment
    -
    maybe_comment
    -
    wrap
    -
    no_identify
    -
    normalize_func
    -
    indent
    -
    sql
    -
    uncache_sql
    -
    cache_sql
    -
    characterset_sql
    -
    column_sql
    -
    columnposition_sql
    -
    columndef_sql
    -
    columnconstraint_sql
    -
    autoincrementcolumnconstraint_sql
    -
    compresscolumnconstraint_sql
    -
    generatedasidentitycolumnconstraint_sql
    -
    notnullcolumnconstraint_sql
    -
    primarykeycolumnconstraint_sql
    -
    uniquecolumnconstraint_sql
    -
    createable_sql
    -
    create_sql
    -
    clone_sql
    -
    describe_sql
    -
    prepend_ctes
    -
    with_sql
    -
    cte_sql
    -
    tablealias_sql
    -
    bitstring_sql
    -
    hexstring_sql
    -
    bytestring_sql
    -
    rawstring_sql
    -
    datatypesize_sql
    -
    datatype_sql
    -
    directory_sql
    -
    delete_sql
    -
    drop_sql
    -
    except_sql
    -
    except_op
    -
    fetch_sql
    -
    filter_sql
    -
    hint_sql
    -
    index_sql
    -
    identifier_sql
    -
    inputoutputformat_sql
    -
    national_sql
    -
    partition_sql
    -
    properties_sql
    -
    root_properties
    -
    properties
    -
    with_properties
    -
    locate_properties
    -
    property_sql
    -
    likeproperty_sql
    -
    fallbackproperty_sql
    -
    journalproperty_sql
    -
    freespaceproperty_sql
    -
    checksumproperty_sql
    -
    mergeblockratioproperty_sql
    -
    datablocksizeproperty_sql
    -
    blockcompressionproperty_sql
    -
    isolatedloadingproperty_sql
    -
    lockingproperty_sql
    -
    withdataproperty_sql
    -
    insert_sql
    -
    intersect_sql
    -
    intersect_op
    -
    introducer_sql
    -
    pseudotype_sql
    -
    onconflict_sql
    -
    returning_sql
    -
    rowformatdelimitedproperty_sql
    -
    withtablehint_sql
    -
    indextablehint_sql
    -
    table_sql
    -
    tablesample_sql
    -
    pivot_sql
    -
    tuple_sql
    -
    update_sql
    -
    values_sql
    -
    var_sql
    -
    into_sql
    -
    from_sql
    -
    group_sql
    -
    having_sql
    -
    join_sql
    -
    lambda_sql
    -
    lateral_sql
    -
    setitem_sql
    -
    set_sql
    -
    pragma_sql
    -
    lock_sql
    -
    literal_sql
    -
    escape_str
    -
    loaddata_sql
    -
    null_sql
    -
    boolean_sql
    -
    order_sql
    -
    cluster_sql
    -
    distribute_sql
    -
    sort_sql
    -
    ordered_sql
    -
    matchrecognize_sql
    -
    query_modifiers
    -
    offset_limit_modifiers
    -
    after_having_modifiers
    -
    after_limit_modifiers
    -
    select_sql
    -
    schema_sql
    -
    schema_columns_sql
    -
    star_sql
    -
    parameter_sql
    -
    sessionparameter_sql
    -
    placeholder_sql
    -
    subquery_sql
    -
    qualify_sql
    -
    union_sql
    -
    union_op
    -
    unnest_sql
    -
    where_sql
    -
    window_sql
    -
    partition_by_sql
    -
    windowspec_sql
    -
    withingroup_sql
    -
    between_sql
    -
    bracket_sql
    -
    safebracket_sql
    -
    all_sql
    -
    any_sql
    -
    exists_sql
    -
    case_sql
    -
    constraint_sql
    -
    nextvaluefor_sql
    -
    extract_sql
    -
    trim_sql
    -
    safeconcat_sql
    -
    check_sql
    -
    foreignkey_sql
    -
    primarykey_sql
    -
    if_sql
    -
    matchagainst_sql
    -
    jsonkeyvalue_sql
    -
    jsonobject_sql
    -
    openjsoncolumndef_sql
    -
    openjson_sql
    -
    in_sql
    -
    in_unnest_op
    -
    interval_sql
    -
    return_sql
    -
    reference_sql
    -
    anonymous_sql
    -
    paren_sql
    -
    neg_sql
    -
    not_sql
    -
    alias_sql
    -
    aliases_sql
    -
    attimezone_sql
    -
    add_sql
    -
    and_sql
    -
    connector_sql
    -
    bitwiseand_sql
    -
    bitwiseleftshift_sql
    -
    bitwisenot_sql
    -
    bitwiseor_sql
    -
    bitwiserightshift_sql
    -
    bitwisexor_sql
    -
    currentdate_sql
    -
    collate_sql
    -
    command_sql
    -
    comment_sql
    -
    mergetreettlaction_sql
    -
    mergetreettl_sql
    -
    transaction_sql
    -
    commit_sql
    -
    rollback_sql
    -
    altercolumn_sql
    -
    renametable_sql
    -
    altertable_sql
    -
    droppartition_sql
    -
    addconstraint_sql
    -
    distinct_sql
    -
    ignorenulls_sql
    -
    respectnulls_sql
    -
    intdiv_sql
    -
    dpipe_sql
    -
    safedpipe_sql
    -
    div_sql
    -
    overlaps_sql
    -
    distance_sql
    -
    dot_sql
    -
    eq_sql
    -
    escape_sql
    -
    glob_sql
    -
    gt_sql
    -
    gte_sql
    -
    ilike_sql
    -
    ilikeany_sql
    -
    is_sql
    -
    like_sql
    -
    likeany_sql
    -
    similarto_sql
    -
    lt_sql
    -
    lte_sql
    -
    mod_sql
    -
    mul_sql
    -
    neq_sql
    -
    nullsafeeq_sql
    -
    nullsafeneq_sql
    -
    or_sql
    -
    slice_sql
    -
    sub_sql
    -
    trycast_sql
    -
    use_sql
    -
    binary
    -
    function_fallback_sql
    -
    func
    -
    format_args
    -
    text_width
    -
    format_time
    -
    expressions
    -
    op_expressions
    -
    naked_property
    -
    set_operation
    -
    tag_sql
    -
    token_sql
    -
    userdefinedfunction_sql
    -
    joinhint_sql
    -
    kwarg_sql
    -
    when_sql
    -
    merge_sql
    -
    tochar_sql
    -
    dictproperty_sql
    -
    dictrange_sql
    -
    dictsubproperty_sql
    -
    oncluster_sql
    -
    clusteredbyproperty_sql
    -
    anyvalue_sql
    -
    querytransform_sql
    -
    indexconstraintoption_sql
    -
    indexcolumnconstraint_sql
    - -
    - -
    -
    -
    -
    - - \ No newline at end of file diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index 09e86b960a..c857bc3123 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -12,7 +12,7 @@ from sqlglot.helper import seq_get -def _to_date_sql(self: generator.Generator, expression: exp.TsOrDsToDate) -> str: +def _to_date_sql(self: MySQL.Generator, expression: exp.TsOrDsToDate) -> str: this = self.sql(expression, "this") self.format_time(expression) return f"TO_DATE({this})" @@ -59,6 +59,7 @@ class Parser(MySQL.Parser): "DATE_TRUNC": lambda args: exp.TimestampTrunc( this=seq_get(args, 1), unit=seq_get(args, 0) ), + "REGEXP": exp.RegexpLike.from_arg_list, } class Generator(MySQL.Generator): @@ -74,38 +75,31 @@ class Generator(MySQL.Generator): TRANSFORMS = { **MySQL.Generator.TRANSFORMS, exp.ApproxDistinct: approx_count_distinct_sql, + exp.ArrayAgg: rename_func("COLLECT_LIST"), + exp.Coalesce: rename_func("NVL"), + exp.CurrentTimestamp: lambda *_: "NOW()", + exp.DateTrunc: lambda self, e: self.func( + "DATE_TRUNC", e.this, "'" + e.text("unit") + "'" + ), exp.JSONExtractScalar: arrow_json_extract_sql, exp.JSONExtract: arrow_json_extract_sql, - exp.DateDiff: rename_func("DATEDIFF"), exp.RegexpLike: rename_func("REGEXP"), - exp.Coalesce: rename_func("NVL"), - exp.CurrentTimestamp: lambda self, e: "NOW()", - exp.TimeToStr: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", - exp.ToChar: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", + exp.RegexpSplit: rename_func("SPLIT_BY_STRING"), + exp.SetAgg: rename_func("COLLECT_SET"), exp.StrToUnix: lambda self, e: f"UNIX_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})", - exp.TimestampTrunc: lambda self, e: self.func( - "DATE_TRUNC", exp.Literal.string(e.text("unit")), e.this - ), + exp.Split: rename_func("SPLIT_BY_STRING"), exp.TimeStrToDate: rename_func("TO_DATE"), - exp.UnixToStr: lambda self, e: self.func( - "FROM_UNIXTIME", e.this, _time_format(self, e) - ), - exp.UnixToTime: rename_func("FROM_UNIXTIME"), - exp.ArrayAgg: rename_func("COLLECT_LIST"), - exp.SetAgg: rename_func("COLLECT_SET"), - exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", # Only for day level + exp.ToChar: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", + exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})",# Only for day level exp.TsOrDsToDate: _to_date_sql, - exp.Map: rename_func("ARRAY_MAP"), - exp.RegexpSplit: rename_func("SPLIT_BY_STRING"), - exp.Split: rename_func("SPLIT_BY_STRING"), - exp.Quantile: rename_func("PERCENTILE"), - exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), - exp.DateTrunc: lambda self, e: self.func( - "DATE_TRUNC", e.this, "'" + e.text("unit") + "'" - ), exp.TimestampTrunc: lambda self, e: self.func( "DATE_TRUNC", e.this, "'" + e.text("unit") + "'" ), + exp.UnixToStr: lambda self, e: self.func( + "FROM_UNIXTIME", e.this, _time_format(self, e) + ), + exp.UnixToTime: rename_func("FROM_UNIXTIME"), + exp.Map: rename_func("ARRAY_MAP"), } From 85b350a06926eff600e2e43479a8559530df34a9 Mon Sep 17 00:00:00 2001 From: liujiwen-up Date: Wed, 9 Aug 2023 14:29:12 +0800 Subject: [PATCH 10/12] Clean up the code and revert any changes in the html --- docs/sqlglot/dialects/dialect.html | 3 --- sqlglot/dialects/doris.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/sqlglot/dialects/dialect.html b/docs/sqlglot/dialects/dialect.html index 1c948baa4c..54a7d8b6d9 100644 --- a/docs/sqlglot/dialects/dialect.html +++ b/docs/sqlglot/dialects/dialect.html @@ -96,9 +96,6 @@

    API Documentation

  • TSQL
  • -
  • - DORIS -
  • diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index c857bc3123..3809117ba0 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -90,7 +90,7 @@ class Generator(MySQL.Generator): exp.Split: rename_func("SPLIT_BY_STRING"), exp.TimeStrToDate: rename_func("TO_DATE"), exp.ToChar: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", - exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})",# Only for day level + exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", # Only for day level exp.TsOrDsToDate: _to_date_sql, exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), From deed875f1f8232f2b358c2d4a6c2709020f1be5e Mon Sep 17 00:00:00 2001 From: Jo <46752250+GeorgeSittas@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:31:38 +0300 Subject: [PATCH 11/12] Update docs/sqlglot/dialects/dialect.html --- docs/sqlglot/dialects/dialect.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/sqlglot/dialects/dialect.html b/docs/sqlglot/dialects/dialect.html index 54a7d8b6d9..be447f4ee2 100644 --- a/docs/sqlglot/dialects/dialect.html +++ b/docs/sqlglot/dialects/dialect.html @@ -1396,8 +1396,6 @@

    - -
    Inherited Members
    From b43383fe08e4cc684ed0377d58a7615af62f6d76 Mon Sep 17 00:00:00 2001 From: Jo <46752250+GeorgeSittas@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:32:02 +0300 Subject: [PATCH 12/12] Update sqlglot/dialects/doris.py --- sqlglot/dialects/doris.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py index 3809117ba0..50e18ad1f8 100644 --- a/sqlglot/dialects/doris.py +++ b/sqlglot/dialects/doris.py @@ -91,7 +91,7 @@ class Generator(MySQL.Generator): exp.TimeStrToDate: rename_func("TO_DATE"), exp.ToChar: lambda self, e: f"DATE_FORMAT({self.sql(e, 'this')}, {self.format_time(e)})", exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", # Only for day level - exp.TsOrDsToDate: _to_date_sql, + exp.TsOrDsToDate: lambda self, e: self.func("TO_DATE", e.this), exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), exp.TimestampTrunc: lambda self, e: self.func(