zhuqi-lucas opened a new issue, #26409: URL: https://github.com/apache/datafusion/issues/26409
### Is your feature request related to a problem or challenge? `array_agg(x ORDER BY y)` has no `GroupsAccumulator`: `groups_accumulator_supported` requires `order_bys` to be empty, so every grouped ordered `ARRAY_AGG` goes through `GroupsAccumulatorAdapter`, with one `OrderSensitiveArrayAggAccumulator` per group. High-cardinality `GROUP BY` queries then pay the adapter's per-group allocation, per-group dispatch and `ScalarValue` output costs. #26357 adds a native groups accumulator for `array_agg(DISTINCT x)`, including `ORDER BY x`. The general `ORDER BY y` case is still on the adapter path. ### Describe the solution you'd like A native groups accumulator for ordered `ARRAY_AGG`, along the lines of #26357 and the ordered `first_value`/`last_value` groups accumulators: - Store values and ordering keys in shared buffers for all groups, plus a `(group_index, row_index)` entry per value, instead of one accumulator per group. - In `evaluate`, counting-sort the entries by group, then sort each group's slice by its ordering key. - When `is_input_pre_ordered` is set (the input already satisfies the ordering), skip the per-group sort for raw input. States merged from several partitions still need sorting. ### Describe alternatives you've considered Keep the adapter. #25199 reduced the per-group memory of `OrderSensitiveArrayAggAccumulator`, but the per-group accumulator and dispatch remain. ### Additional context Follow-up to #26347 / #26357. I'd like to work on this. -- 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]
