feat: use dialect when tokenizing (#30614)

This commit is contained in:
Beto Dealmeida 2024-10-15 14:32:02 -04:00 committed by GitHub
parent d6b2e86155
commit 4cac7feb67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -276,7 +276,7 @@ class SQLStatement(BaseSQLStatement[exp.Expression]):
script: str,
engine: str,
) -> list[SQLStatement]:
if engine in SQLGLOT_DIALECTS:
if dialect := SQLGLOT_DIALECTS.get(engine):
try:
return [
cls(ast.sql(), engine, ast)
@ -297,7 +297,7 @@ class SQLStatement(BaseSQLStatement[exp.Expression]):
remainder = script
try:
tokens = sqlglot.tokenize(script)
tokens = sqlglot.tokenize(script, dialect)
except sqlglot.errors.TokenError as ex:
raise SupersetParseError(
script,

View File

@ -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