diff --git a/superset/sql/parse.py b/superset/sql/parse.py index 314ddb40dd7..20fe7f2b0c8 100644 --- a/superset/sql/parse.py +++ b/superset/sql/parse.py @@ -1557,7 +1557,7 @@ def sanitize_clause(clause: str, engine: str) -> str: return Dialect.get_or_raise(dialect).generate( statement._parsed, # pylint: disable=protected-access copy=True, - comments=False, + comments=True, pretty=False, ) except SupersetParseError as ex: diff --git a/tests/unit_tests/sql/parse_tests.py b/tests/unit_tests/sql/parse_tests.py index 274acc01b5a..78b00f4487d 100644 --- a/tests/unit_tests/sql/parse_tests.py +++ b/tests/unit_tests/sql/parse_tests.py @@ -2693,9 +2693,19 @@ def test_is_valid_cvas(sql: str, engine: str, expected: bool) -> None: ), # Compact format ( "col = 'abc' -- comment", - "col = 'abc'", + "col = 'abc' /* comment */", "base", - ), # Comments removed for compact format + ), # Line comments converted to block comments + ( + "TRUE /* precise_count_distinct=true */", + "TRUE /* precise_count_distinct=true */", + "base", + ), # Block comments preserved + ( + "col > 1 /* hint=value */", + "col > 1 /* hint=value */", + "base", + ), # Block comments preserved ("col = 'col1 = 1) AND (col2 = 2'", "col = 'col1 = 1) AND (col2 = 2'", "base"), ("col = 'select 1; select 2'", "col = 'select 1; select 2'", "base"), ("col = 'abc -- comment'", "col = 'abc -- comment'", "base"),