Skip to content

Commit

Permalink
Fix: is true for presto closes #1740
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jun 7, 2023
1 parent d2e46c3 commit 0cc09cf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions sqlglot/dialects/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class Generator(generator.Generator):
INTERVAL_ALLOWS_PLURAL_FORM = False
JOIN_HINTS = False
TABLE_HINTS = False
IS_BOOL = False
STRUCT_DELIMITER = ("(", ")")

PROPERTIES_LOCATION = {
Expand Down
5 changes: 5 additions & 0 deletions sqlglot/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class Generator:

JOIN_HINTS = True
TABLE_HINTS = True
IS_BOOL = True

RESERVED_KEYWORDS: t.Set[str] = set()
WITH_SEPARATED_COMMENTS = (exp.Select, exp.From, exp.Where, exp.With)
Expand Down Expand Up @@ -2127,6 +2128,10 @@ def ilikeany_sql(self, expression: exp.ILikeAny) -> str:
return self.binary(expression, "ILIKE ANY")

def is_sql(self, expression: exp.Is) -> str:
if not self.IS_BOOL and isinstance(expression.expression, exp.Boolean):
return self.sql(
expression.this if expression.expression.this else exp.not_(expression.this)
)
return self.binary(expression, "IS")

def like_sql(self, expression: exp.Like) -> str:
Expand Down
23 changes: 23 additions & 0 deletions tests/dialects/test_redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ def test_redshift(self):
},
)

self.validate_all(
"x is true",
write={
"redshift": "x IS TRUE",
"presto": "x",
},
)
self.validate_all(
"x is false",
write={
"redshift": "x IS FALSE",
"presto": "NOT x",
},
)

self.validate_all(
"x is not false",
write={
"redshift": "NOT x IS FALSE",
"presto": "NOT NOT x",
},
)

self.validate_all(
"SELECT SYSDATE",
write={
Expand Down

0 comments on commit 0cc09cf

Please sign in to comment.