fix: engines that don't support comments (#13153)

* fix: engines that don't support comments

* fix: engines that don't support comments

* add quick inexpensive test

* add test
This commit is contained in:
Daniel Vaz Gaspar
2021-02-17 18:01:34 +00:00
committed by GitHub
parent e1bb7f4364
commit 9568985b7b
5 changed files with 53 additions and 2 deletions

View File

@@ -18,7 +18,7 @@ import unittest
import sqlparse
from superset.sql_parse import ParsedQuery, Table
from superset.sql_parse import ParsedQuery, strip_comments_from_sql, Table
class TestSupersetSqlParse(unittest.TestCase):
@@ -732,3 +732,19 @@ class TestSupersetSqlParse(unittest.TestCase):
"""
parsed = ParsedQuery(query, strip_comments=True)
assert not parsed.is_valid_ctas()
def test_strip_comments_from_sql(self):
"""Test that we are able to strip comments out of SQL stmts"""
assert (
strip_comments_from_sql("SELECT col1, col2 FROM table1")
== "SELECT col1, col2 FROM table1"
)
assert (
strip_comments_from_sql("SELECT col1, col2 FROM table1\n-- comment")
== "SELECT col1, col2 FROM table1\n"
)
assert (
strip_comments_from_sql("SELECT '--abc' as abc, col2 FROM table1\n")
== "SELECT '--abc' as abc, col2 FROM table1"
)