fix: is_select with UNION (#25290)

This commit is contained in:
Beto Dealmeida
2023-09-14 09:05:19 -07:00
committed by GitHub
parent e1ddba9c0f
commit bb002d6147
2 changed files with 17 additions and 3 deletions

View File

@@ -229,13 +229,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