fix(sql): detect set operations and nested selects in subquery check (#38452)

Co-authored-by: sha174n <pedro.sousa@preset.io>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Shaitan
2026-06-23 04:27:32 +01:00
committed by GitHub
parent 3b46a5f121
commit 215b207ae4
2 changed files with 20 additions and 6 deletions

View File

@@ -3549,6 +3549,17 @@ def test_tokenize_kql(kql: str, expected: list[tuple[KQLTokenType, str]]) -> Non
"postgresql",
True,
),
# Set operations: a top-level UNION/INTERSECT/EXCEPT is not an
# exp.Subquery, so it must be detected explicitly. A predicate fragment
# that introduces one (e.g. supplied through a chart filter) must be
# flagged.
("true UNION SELECT name FROM other_table", "postgresql", True),
("1 = 1 UNION ALL SELECT password FROM users", "postgresql", True),
("SELECT 1 INTERSECT SELECT 2", "postgresql", True),
("SELECT 1 EXCEPT SELECT 2", "postgresql", True),
# Nested SELECT under non-Select top-level nodes (e.g. extra
# parentheses) must still be detected.
("name IN (((SELECT secret FROM s)))", "postgresql", True),
],
)
def test_has_subquery(sql: str, engine: str, expected: bool) -> None: