diff --git a/superset/sql_parse.py b/superset/sql_parse.py index f84d73bef032a..03c9926a44a55 100644 --- a/superset/sql_parse.py +++ b/superset/sql_parse.py @@ -228,7 +228,7 @@ def is_select(self) -> bool: # 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 @@ def is_select(self) -> bool: 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 ba3da69aaefaf..f6d63cf465236 100644 --- a/tests/unit_tests/sql_parse_tests.py +++ b/tests/unit_tests/sql_parse_tests.py @@ -1008,6 +1008,28 @@ def test_cte_is_select() -> None: 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.