kumarUjjawal commented on issue #19322: URL: https://github.com/apache/datafusion/issues/19322#issuecomment-3693042381
I checked how DuckDB, PostgreSQL, and Spark handle `median()` for integer inputs. All three databases return `Float64`/`Double` for median calculations, which avoids both the overflow issue and truncation loss. **DuckDB** defines `median(x)` as an alias for `quantile_cont(x, 0.5)` ([docs](https://duckdb.org/docs/stable/sql/functions/aggregates.html#medianx)). The return type is always `DOUBLE` for all continuous quantile types. (https://github.com/duckdb/duckdb/blob/v1.1.3/src/core_functions/aggregate/holistic/quantile.cpp) **PostgreSQL** doesn't have a built-in `median()` function but uses. `percentile_cont(0.5)` which returns `double precision`. (https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/orderedsetaggs.c). **Apache Spark** implements `median()` as equivalent to `percentile_cont(0.5)` ([docs](https://spark.apache.org/docs/latest/api/sql/index.html#median)). (https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/percentiles.scal) -- 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]
