Skip to content

Commit 0b419a0

Browse files
authored
fix: add comments to SQL clause validation (#39167)
1 parent 0b51e9c commit 0b419a0

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

superset/sql/parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ def sanitize_clause(clause: str, engine: str) -> str:
15571557
return Dialect.get_or_raise(dialect).generate(
15581558
statement._parsed, # pylint: disable=protected-access
15591559
copy=True,
1560-
comments=False,
1560+
comments=True,
15611561
pretty=False,
15621562
)
15631563
except SupersetParseError as ex:

tests/unit_tests/sql/parse_tests.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,9 +2693,19 @@ def test_is_valid_cvas(sql: str, engine: str, expected: bool) -> None:
26932693
), # Compact format
26942694
(
26952695
"col = 'abc' -- comment",
2696-
"col = 'abc'",
2696+
"col = 'abc' /* comment */",
26972697
"base",
2698-
), # Comments removed for compact format
2698+
), # Line comments converted to block comments
2699+
(
2700+
"TRUE /* precise_count_distinct=true */",
2701+
"TRUE /* precise_count_distinct=true */",
2702+
"base",
2703+
), # Block comments preserved
2704+
(
2705+
"col > 1 /* hint=value */",
2706+
"col > 1 /* hint=value */",
2707+
"base",
2708+
), # Block comments preserved
26992709
("col = 'col1 = 1) AND (col2 = 2'", "col = 'col1 = 1) AND (col2 = 2'", "base"),
27002710
("col = 'select 1; select 2'", "col = 'select 1; select 2'", "base"),
27012711
("col = 'abc -- comment'", "col = 'abc -- comment'", "base"),

0 commit comments

Comments
 (0)