Skip to content

Commit

Permalink
Fix(presto): transpile BIT to BOOLEAN
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas committed Oct 18, 2024
1 parent 83167ea commit 7a5c7e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 7 additions & 6 deletions sqlglot/dialects/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
10 changes: 10 additions & 0 deletions tests/dialects/test_presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down

0 comments on commit 7a5c7e0

Please sign in to comment.