From 0316f7f73ef8c7e065dd3e373c0eea98cb0c3156 Mon Sep 17 00:00:00 2001 From: barak Date: Fri, 25 Aug 2023 09:27:58 -0700 Subject: [PATCH] fix(presto): datetime -> timestamp (#2113) * fix(presto): datetime -> timestamp * Fixup --- sqlglot/dialects/presto.py | 2 ++ tests/dialects/test_dialect.py | 3 ++- tests/dialects/test_presto.py | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sqlglot/dialects/presto.py b/sqlglot/dialects/presto.py index 6784188f8c..9e8bb9ccd7 100644 --- a/sqlglot/dialects/presto.py +++ b/sqlglot/dialects/presto.py @@ -265,6 +265,8 @@ class Generator(generator.Generator): exp.DataType.Type.TIMETZ: "TIME", exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP", exp.DataType.Type.STRUCT: "ROW", + exp.DataType.Type.DATETIME: "TIMESTAMP", + exp.DataType.Type.DATETIME64: "TIMESTAMP", } TRANSFORMS = { diff --git a/tests/dialects/test_dialect.py b/tests/dialects/test_dialect.py index 29507cdce5..1bfe62adea 100644 --- a/tests/dialects/test_dialect.py +++ b/tests/dialects/test_dialect.py @@ -30,9 +30,10 @@ def validate_all(self, sql, read=None, write=None, pretty=False, identify=False) Args: sql (str): Main SQL expression - dialect (str): dialect of `sql` read (dict): Mapping of dialect -> SQL write (dict): Mapping of dialect -> SQL + pretty (bool): prettify both read and write + identify (bool): quote identifiers in both read and write """ expression = self.parse_one(sql) diff --git a/tests/dialects/test_presto.py b/tests/dialects/test_presto.py index 1d0b90710f..560bb7a917 100644 --- a/tests/dialects/test_presto.py +++ b/tests/dialects/test_presto.py @@ -346,6 +346,11 @@ def test_time(self): "presto": "SELECT CAST('2012-10-31 00:00' AS TIMESTAMP) AT TIME ZONE 'America/Sao_Paulo'", }, ) + self.validate_all( + "CAST(x AS TIMESTAMP)", + write={"presto": "CAST(x AS TIMESTAMP)"}, + read={"mysql": "CAST(x AS DATETIME)", "clickhouse": "CAST(x AS DATETIME64)"}, + ) def test_ddl(self): self.validate_all(