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

fix: sqlparse fallback for formatting queries #30578

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

Conversation

betodealmeida
Copy link
Member

SUMMARY

An improvement to #30350.

Today, when a DB engine spec has no corresponding sqlglot dialect, we use a generic one to parse queries, which works fine. When converting the AST back to a string to pretty-print SQL, though, we hit a problem: in some databases the query becomes invalid. For example, this Firebolt query:

SELECT col FROM t WHERE col NOT IN (1, 2);

Gets formatted to:

SELECT col FROM t WHERE NOT col IN (1, 2);

While equivalent, the latter is invalid in Firebolt.

The long term solution is to add a Firebolt dialect to sqlglot, at least handling this edge case. As a more generic solution, this PR implements logic where, when a DB engine spec doesn't have a corresponding dialect in sqlglot, the query is pretty-printed using sqlparse.format. This way we have the strictness and correctness of sqlglot when parsing queries, and the leniency of sqlparse when formatting them.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

Added unit tests covering the problem.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

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

Successfully merging this pull request may close these issues.

1 participant