summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/doris.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/dialects/doris.py')
-rw-r--r--sqlglot/dialects/doris.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/sqlglot/dialects/doris.py b/sqlglot/dialects/doris.py
index 9a84848..f4ec0e5 100644
--- a/sqlglot/dialects/doris.py
+++ b/sqlglot/dialects/doris.py
@@ -7,6 +7,7 @@ from sqlglot.dialects.dialect import (
build_timestamp_trunc,
rename_func,
time_format,
+ unit_to_str,
)
from sqlglot.dialects.mysql import MySQL
@@ -27,7 +28,7 @@ class Doris(MySQL):
}
class Generator(MySQL.Generator):
- CAST_MAPPING = {}
+ LAST_DAY_SUPPORTS_DATE_PART = False
TYPE_MAPPING = {
**MySQL.Generator.TYPE_MAPPING,
@@ -36,8 +37,7 @@ class Doris(MySQL):
exp.DataType.Type.TIMESTAMPTZ: "DATETIME",
}
- LAST_DAY_SUPPORTS_DATE_PART = False
-
+ CAST_MAPPING = {}
TIMESTAMP_FUNC_TYPES = set()
TRANSFORMS = {
@@ -49,9 +49,7 @@ class Doris(MySQL):
exp.ArrayAgg: rename_func("COLLECT_LIST"),
exp.ArrayUniqueAgg: rename_func("COLLECT_SET"),
exp.CurrentTimestamp: lambda self, _: self.func("NOW"),
- exp.DateTrunc: lambda self, e: self.func(
- "DATE_TRUNC", e.this, "'" + e.text("unit") + "'"
- ),
+ exp.DateTrunc: lambda self, e: self.func("DATE_TRUNC", e.this, unit_to_str(e)),
exp.JSONExtractScalar: arrow_json_extract_sql,
exp.JSONExtract: arrow_json_extract_sql,
exp.Map: rename_func("ARRAY_MAP"),
@@ -63,9 +61,7 @@ class Doris(MySQL):
exp.TsOrDsAdd: lambda self, e: self.func("DATE_ADD", e.this, e.expression),
exp.TsOrDsToDate: lambda self, e: self.func("TO_DATE", e.this),
exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"),
- exp.TimestampTrunc: lambda self, e: self.func(
- "DATE_TRUNC", e.this, "'" + e.text("unit") + "'"
- ),
+ exp.TimestampTrunc: lambda self, e: self.func("DATE_TRUNC", e.this, unit_to_str(e)),
exp.UnixToStr: lambda self, e: self.func(
"FROM_UNIXTIME", e.this, time_format("doris")(self, e)
),