This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 4cac7feb67 feat: use dialect when tokenizing (#30614)
4cac7feb67 is described below

commit 4cac7feb675794a75b6604610b1da97cf0b1b339
Author: Beto Dealmeida <[email protected]>
AuthorDate: Tue Oct 15 14:32:02 2024 -0400

    feat: use dialect when tokenizing (#30614)
---
 superset/sql/parse.py               | 4 ++--
 tests/unit_tests/sql_parse_tests.py | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/superset/sql/parse.py b/superset/sql/parse.py
index 33ed76473f..2c7276baba 100644
--- a/superset/sql/parse.py
+++ b/superset/sql/parse.py
@@ -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,
diff --git a/tests/unit_tests/sql_parse_tests.py 
b/tests/unit_tests/sql_parse_tests.py
index 44d52c7f6e..cf6eda3dda 100644
--- a/tests/unit_tests/sql_parse_tests.py
+++ b/tests/unit_tests/sql_parse_tests.py
@@ -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

Reply via email to