fix: CTAS on multiple statements (#12188)

* WIP

* Add unit tests for sql_parse

* Add unit tests for sql_lab
This commit is contained in:
Beto Dealmeida
2021-01-04 09:22:35 -08:00
committed by GitHub
parent ff0fe434e4
commit 164db3e5a1
4 changed files with 295 additions and 13 deletions

View File

@@ -81,7 +81,10 @@ class Table: # pylint: disable=too-few-public-methods
class ParsedQuery:
def __init__(self, sql_statement: str):
def __init__(self, sql_statement: str, strip_comments: bool = False):
if strip_comments:
sql_statement = sqlparse.format(sql_statement, strip_comments=True)
self.sql: str = sql_statement
self._tables: Set[Table] = set()
self._alias_names: Set[str] = set()
@@ -110,6 +113,12 @@ class ParsedQuery:
def is_select(self) -> bool:
return self._parsed[0].get_type() == "SELECT"
def is_valid_ctas(self) -> bool:
return self._parsed[-1].get_type() == "SELECT"
def is_valid_cvas(self) -> bool:
return len(self._parsed) == 1 and self._parsed[0].get_type() == "SELECT"
def is_explain(self) -> bool:
# Remove comments
statements_without_comments = sqlparse.format(