mirror of
https://github.com/apache/superset.git
synced 2026-07-13 18:25:58 +00:00
`sanitize_clause` round-tripped the user's clause through SQLGlot's dialect generator and returned the re-rendered SQL. SQLGlot's Postgres dialect (borrowed by engines such as Redshift, CockroachDB, Netezza and SAP HANA) rewrites `ROUND(AVG(x), n)` into `ROUND(CAST(AVG(x) AS DECIMAL), n)`. On engines whose unqualified DECIMAL defaults to scale 0, that injected cast rounds the aggregate to an integer before the explicit ROUND, so `ROUND(AVG(0.949583), 4)` returns `1` instead of `0.9496`. This regressed when validation moved from sqlparse to SQLGlot; the legacy implementation only validated the clause and returned it unchanged. Validate by parsing as before, but return the original clause verbatim. Clauses that contain comments are still re-rendered, since a trailing line comment can comment out surrounding SQL once the clause is embedded into a larger query. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>