fix: is_select with UNION (#25290)

(cherry picked from commit bb002d6147)
This commit is contained in:
Beto Dealmeida
2023-09-14 09:05:19 -07:00
committed by Michael S. Molina
parent 40d9c4c81f
commit 807a027a5f
2 changed files with 17 additions and 3 deletions

View File

@@ -230,13 +230,17 @@ class ParsedQuery:
:param oxide_parse: parsed CTE
:return: True if CTE is a SELECT statement
"""
def is_body_select(body: dict[str, Any]) -> bool:
if op := body.get("SetOperation"):
return is_body_select(op["left"]) and is_body_select(op["right"])
return all(key == "Select" for key in body.keys())
for query in oxide_parse:
parsed_query = query["Query"]
cte_tables = self._get_cte_tables(parsed_query)
for cte_table in cte_tables:
is_select = all(
key == "Select" for key in cte_table["query"]["body"].keys()
)
is_select = is_body_select(cte_table["query"]["body"])
if not is_select:
return False
return True