bito-code-review[bot] commented on code in PR #42895:
URL: https://github.com/apache/superset/pull/42895#discussion_r3829841965
##########
superset-frontend/src/explore/components/controls/MetricControl/AdhocMetric.ts:
##########
@@ -153,6 +153,19 @@ export default class AdhocMetric {
) {
return `COUNT(DISTINCT ${column.slice(1, -1)})`;
}
+ // MEDIAN(column) isn't a real function on every engine this PR
+ // verifies it for -- PostgreSQL/Redshift compile it to
+ // PERCENTILE_CONT(0.5) WITHIN GROUP instead. `transformCountDistinct`
+ // signals this call is prefilling the *editable, executable* Custom
+ // SQL tab (not just a display label), so use the portable,
+ // standards-based spelling there instead of the raw aggregate name.
+ if (
+ params.transformCountDistinct &&
+ aggregate === AGGREGATES.MEDIAN &&
+ /^\(.*\)$/.test(column)
+ ) {
+ return `PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY ${column.slice(1,
-1)})`;
+ }
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Wrong SQL for non-Postgres engines</b></div>
<div id="fix">
The MEDIAN→PERCENTILE_CONT transformation at lines 162-168 applies
unconditionally to ALL database engines, including DuckDB, Snowflake, BigQuery,
Redshift, Oracle, T-SQL, Databricks, and Spark — all of which have a native
`MEDIAN(x)` function per SIP documentation and engine specs. This generates
incorrect SQL for those engines. The backend's `_extended_aggregations` map
(postgres.py line 211, duckdb.py line 214) already handles engine-specific
MEDIAN translation correctly at query execution time; the frontend rewrite
bypasses this and overrides it with a Postgres-only form.
</div>
</div>
<small><i>Code Review Run #adf52b</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]