RainierLarry opened a new issue, #13745: URL: https://github.com/apache/gluten/issues/13745
### Description A Velox streaming aggregate (`isStreamingAgg=true`) emits groups in input order, like vanilla Spark's `SortAggregateExec`. But `HashAggregateExecBaseTransformer` never reports an `outputOrdering`, so the planner treats its output as unsorted. Two costs follow: 1. A sort merge join on the aggregate's grouping keys gets a full local sort above the aggregate, re-sorting data that is already sorted. Vanilla Spark needs no sort there. 2. A second aggregate on a prefix of the keys can't stream, so it runs as a hash aggregate and may spill, where vanilla Spark would plan a sort aggregate. Proposal: report the grouping keys (ascending) as the output ordering when the aggregate streams and the backend keeps input order (Velox, non-flushable aggregates), behind a config. This needs one rule-order change: `EnsureLocalSortRequirements` runs before `EliminateLocalSort` in `VeloxRuleApi`. Once an aggregate reports an ordering, Ensure can trust it for a parent join, and Eliminate can then remove the local sort the aggregate streams over, leaving the join with unsorted input. Running Eliminate first, then Ensure, adds back any sort that is still needed. This issue was written with the assistance of AI. ### Gluten version None -- 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]
