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: use dialect when tokenizing #30614

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions superset/sql/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def split_script(
script: str,
engine: str,
) -> list[SQLStatement]:
if engine in SQLGLOT_DIALECTS:
if dialect := SQLGLOT_DIALECTS.get(engine):
try:
return [
cls(ast.sql(), engine, ast)
Expand All @@ -297,7 +297,7 @@ def split_script(
remainder = script

try:
tokens = sqlglot.tokenize(script)
tokens = sqlglot.tokenize(script, dialect)
except sqlglot.errors.TokenError as ex:
raise SupersetParseError(
script,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/sql_parse_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_extract_tables_illdefined() -> None:
extract_tables('SELECT * FROM "tbname')
assert (
str(excinfo.value)
== "You may have an error in your SQL statement. Unable to parse script"
== "You may have an error in your SQL statement. Unable to tokenize script"
)

# odd edge case that works
Expand Down
Loading