kosiew commented on code in PR #18607: URL: https://github.com/apache/datafusion/pull/18607#discussion_r2517737578
########## docs/source/user-guide/sql/aggregate_functions.md: ########## @@ -48,6 +48,28 @@ FROM employees; Note: When no rows pass the filter, `COUNT` returns `0` while `SUM`/`AVG`/`MIN`/`MAX` return `NULL`. +## WITHIN GROUP / Ordered-set aggregates + +Some aggregate functions support the SQL `WITHIN GROUP (ORDER BY ...)` clause. This clause is used by +ordered-set aggregate functions (for example, percentile and rank-like aggregations) to specify the ordering +of inputs that the aggregate relies on. In DataFusion, only aggregate functions that explicitly opt into +ordered-set semantics via their implementation will accept `WITHIN GROUP`; attempting to use `WITHIN GROUP` +with a regular aggregate (for example `SUM(x) WITHIN GROUP (ORDER BY x)`) will fail during planning with an +error. This matches Postgres semantics and ensures ordered-set behavior is opt-in for user-defined aggregates. + +Example (ordered-set aggregate): + +```sql +percentile_cont(0.5) WITHIN GROUP (ORDER BY value) +``` + +Example (invalid usage — planner will error): + +```sql +-- This will fail: SUM is not an ordered-set aggregate +SELECT SUM(x) WITHIN GROUP (ORDER BY x) FROM t; +``` Review Comment: >ordered-set aggregate functions (for example, percentile and rank-like aggregations) to specify the ordering of inputs that the aggregate relies on. In DataFusion, only aggregate functions that explicitly opt into ordered-set semantics via their implementation will accept `WITHIN GROUP`; attempting to use `WITHIN GROUP` I thought this part gave a good indication of ordered set aggregate functions. -- 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]
