mirror of
https://github.com/apache/superset.git
synced 2026-07-13 18:25:58 +00:00
fix(sql): normalize comment clauses with base dialect to keep #36113 fix
The comment-handling branch of sanitize_clause re-rendered through the engine dialect, which re-applied the Postgres ROUND/CAST rewrite for any clause containing a comment, reintroducing #36113. Re-render with the base dialect instead so comments are normalized without engine-specific semantic rewrites, and add a parametrized regression test for the comment path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -3238,6 +3238,29 @@ def test_sanitize_clause_preserves_aggregation_semantics(engine: str) -> None:
|
||||
assert sanitized == clause
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"engine",
|
||||
["postgresql", "redshift", "cockroachdb", "netezza", "hana", "base", "mysql"],
|
||||
)
|
||||
def test_sanitize_clause_preserves_aggregation_semantics_with_comment(
|
||||
engine: str,
|
||||
) -> None:
|
||||
"""
|
||||
Regression test for https://github.com/apache/superset/issues/36113.
|
||||
|
||||
A clause that contains a comment takes the re-rendering branch of
|
||||
``sanitize_clause``. That branch must normalize comments using the *base*
|
||||
dialect rather than the engine dialect, so it must not re-apply the Postgres
|
||||
``ROUND(AVG(x), n)`` -> ``ROUND(CAST(AVG(x) AS DECIMAL), n)`` rewrite that
|
||||
truncates results on engines where ``DECIMAL`` defaults to scale 0.
|
||||
"""
|
||||
clause = "ROUND(AVG(col), 4) /* precise_count_distinct=true */"
|
||||
sanitized = sanitize_clause(clause, engine)
|
||||
assert "CAST" not in sanitized.upper(), (
|
||||
f"sanitize_clause injected a cast for engine {engine!r}: {sanitized!r}"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"engine",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user