RainierLarry opened a new pull request, #13746: URL: https://github.com/apache/gluten/pull/13746
## What changes are proposed in this pull request? A Velox streaming aggregate emits groups in input order, like `SortAggregateExec`, but `HashAggregateExecBaseTransformer` reported no `outputOrdering`. So a sort merge join on the grouping keys re-sorted the aggregate's output, and an aggregate on a key prefix could not stream. - `HashAggregateExecBaseTransformer` mixes in `OrderPreservingUnaryExecNode` and reports the grouping keys (ascending) when the new config is on, the backend allows it (`canReportOrdering`, default false), and the aggregate streams. The streaming decision is now made once per node (`lazy val`), so the reported ordering and the native plan agree. The plan string shows `reportsOrdering=`. - Velox `HashAggregateExecTransformer` sets `canReportOrdering = !allowFlush`: flushable aggregates may emit rows early, so they don't report an ordering. Other backends are unchanged. - `VeloxRuleApi` runs `EliminateLocalSort` before `EnsureLocalSortRequirements`. With the old order, Ensure could trust an aggregate's ordering for a parent join, and Eliminate could then remove the local sort under that aggregate, leaving the join with unsorted input. Without this change the swap has no effect, because no aggregate reports an ordering. - New config `spark.gluten.sql.columnar.streamingAggregate.reportOrdering` (default true), documented in `docs/Configuration.md`. Fixes #13745 ## How was this patch tested? New `VeloxStreamingAggregateOrderingSuite`; query tests compare results against vanilla Spark, with and without AQE, and use tiny batches so groups span batch boundaries: - A sort merge join on the keys of a streaming aggregate adds no sort; with the config off, the sort stays. - An aggregate on a key prefix of a streaming aggregate streams only when the config is on. - A sort aggregate whose input sort is removed by `EliminateLocalSort` still gets the sort its parent join needs. - A distinct aggregate with flushable partial aggregation under a sort merge join: flushable aggregates report no ordering. - Unit tests: which aggregates report an ordering, and that the new rule order keeps the join's sort while the old order drops it. A version of this change was also validated in a downstream fork with shadow runs of production queries, comparing results against vanilla Spark. ## Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 -- 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]
