You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/04/18 16:00:00 UTC
[superset] branch master updated: fix: is_select check for lowercase select with "WITH" clauses (#22370)
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 e9b4022787 fix: is_select check for lowercase select with "WITH" clauses (#22370)
e9b4022787 is described below
commit e9b4022787897be3e628f5cd18c4787130c9ae8e
Author: Francisco Muniz de Paula Neto <mu...@gmail.com>
AuthorDate: Tue Apr 18 12:59:50 2023 -0300
fix: is_select check for lowercase select with "WITH" clauses (#22370)
---
superset/sql_parse.py | 4 ++--
tests/unit_tests/sql_parse_tests.py | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/superset/sql_parse.py b/superset/sql_parse.py
index f84d73bef0..03c9926a44 100644
--- a/superset/sql_parse.py
+++ b/superset/sql_parse.py
@@ -228,7 +228,7 @@ class ParsedQuery:
# for `UNKNOWN`, check all DDL/DML explicitly: only `SELECT` DML is allowed,
# and no DDL is allowed
if any(token.ttype == DDL for token in parsed[0]) or any(
- token.ttype == DML and token.value != "SELECT" for token in parsed[0]
+ token.ttype == DML and token.normalized != "SELECT" for token in parsed[0]
):
return False
@@ -237,7 +237,7 @@ class ParsedQuery:
return False
return any(
- token.ttype == DML and token.value == "SELECT" for token in parsed[0]
+ token.ttype == DML and token.normalized == "SELECT" for token in parsed[0]
)
def is_valid_ctas(self) -> bool:
diff --git a/tests/unit_tests/sql_parse_tests.py b/tests/unit_tests/sql_parse_tests.py
index ba3da69aae..f6d63cf465 100644
--- a/tests/unit_tests/sql_parse_tests.py
+++ b/tests/unit_tests/sql_parse_tests.py
@@ -1008,6 +1008,28 @@ FROM foo f"""
assert sql.is_select()
+def test_cte_is_select_lowercase() -> None:
+ """
+ Some CTEs with lowercase select are not correctly identified as SELECTS.
+ """
+ sql = ParsedQuery(
+ """WITH foo AS(
+select
+ FLOOR(__time TO WEEK) AS "week",
+ name,
+ COUNT(DISTINCT user_id) AS "unique_users"
+FROM "druid"."my_table"
+GROUP BY 1,2
+)
+select
+ f.week,
+ f.name,
+ f.unique_users
+FROM foo f"""
+ )
+ assert sql.is_select()
+
+
def test_unknown_select() -> None:
"""
Test that `is_select` works when sqlparse fails to identify the type.