Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Firebolt dialect #4598

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

betodealmeida
Copy link
Contributor

We found a problem when using sqlglot in Apache Superset to process (parse, modify the AST, and re-render) Firebolt queries. The problem happens when we run a query with a predicate of col NOT IN and it gets translated to NOT col IN by the generic parser:

>>> sqlglot.parse_one("SELECT * FROM tbl WHERE i NOT IN (1, 2)").sql()
'SELECT * FROM tbl WHERE NOT i IN (1, 2)'

While both queries are semantically equivalent, the first one is valid in Firebolt, while the second is not. This happens because NOT has higher precedence than IN:

CREATE TABLE tbl (i INT, b BOOLEAN, t TEXT);
INSERT INTO tbl VALUES (0, FALSE, 'false'), (1, TRUE, 'true');
SELECT * FROM tbl WHERE NOT i IN (1, 2);

firebolt error: - Line 4, Column 25: operator 'not' for input types (integer) not found, try adding explicit casts

This only happens when checking for a range; equality (and other comparisons) works as expected:

SELECT * FROM tbl WHERE NOT i = 1;   -- this works

This PR introduces a custom Firebolt dialect that fixes the problem:

>>> sqlglot.parse_one("SELECT * FROM tbl WHERE i NOT IN (1, 2)").sql("firebolt")
'SELECT * FROM tbl WHERE NOT (i IN (1, 2))'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant