From 7a5c7e036fa84eb30bcae75829f3cb94503fa99e Mon Sep 17 00:00:00 2001 From: George Sittas Date: Fri, 18 Oct 2024 12:07:40 +0300 Subject: [PATCH] Fix(presto): transpile BIT to BOOLEAN --- sqlglot/dialects/presto.py | 13 +++++++------ tests/dialects/test_presto.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sqlglot/dialects/presto.py b/sqlglot/dialects/presto.py index f41e8b4926..5a3381c0c3 100644 --- a/sqlglot/dialects/presto.py +++ b/sqlglot/dialects/presto.py @@ -326,16 +326,17 @@ class Generator(generator.Generator): TYPE_MAPPING = { **generator.Generator.TYPE_MAPPING, - exp.DataType.Type.INT: "INTEGER", - exp.DataType.Type.FLOAT: "REAL", exp.DataType.Type.BINARY: "VARBINARY", - exp.DataType.Type.TEXT: "VARCHAR", - exp.DataType.Type.TIMETZ: "TIME", - exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP", - exp.DataType.Type.STRUCT: "ROW", + exp.DataType.Type.BIT: "BOOLEAN", exp.DataType.Type.DATETIME: "TIMESTAMP", exp.DataType.Type.DATETIME64: "TIMESTAMP", + exp.DataType.Type.FLOAT: "REAL", exp.DataType.Type.HLLSKETCH: "HYPERLOGLOG", + exp.DataType.Type.INT: "INTEGER", + exp.DataType.Type.STRUCT: "ROW", + exp.DataType.Type.TEXT: "VARCHAR", + exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP", + exp.DataType.Type.TIMETZ: "TIME", } TRANSFORMS = { diff --git a/tests/dialects/test_presto.py b/tests/dialects/test_presto.py index 3d5fbfe807..4c10a45944 100644 --- a/tests/dialects/test_presto.py +++ b/tests/dialects/test_presto.py @@ -13,6 +13,16 @@ def test_cast(self): self.validate_identity("CAST(TDIGEST_AGG(1) AS TDIGEST)") self.validate_identity("CAST(x AS HYPERLOGLOG)") + self.validate_all( + "CAST(x AS BOOLEAN)", + read={ + "tsql": "CAST(x AS BIT)", + }, + write={ + "presto": "CAST(x AS BOOLEAN)", + "tsql": "CAST(x AS BIT)", + }, + ) self.validate_all( "SELECT FROM_ISO8601_TIMESTAMP('2020-05-11T11:15:05')", write={