mrhhsg opened a new pull request, #70929: URL: https://github.com/apache/doris/pull/70929
### What problem does this PR solve? Issue Number: None Problem Summary: In the BE local-shuffle planner, a colocated aggregation can inherit a bucket-distribution requirement without being followed by a shuffled operator. Ordinary and distinct-streaming aggregation can then select their full grouping keys instead of the input distribution key supplied by FE. For example, when a table is bucketed on `k1` but an aggregation groups by `(k1, k2)`, rehashing both columns can produce bucket IDs absent from the executing BE's local bucket map. With partial bucket ownership, affected multi-stage DISTINCT queries fail with `Rows mismatched` in `BUCKET_HASH_SHUFFLE`. ### What is changed? - Preserve the first FE input distribution expression list when the aggregation is colocated, requires bucket distribution, and that list contains a nonempty key. - Apply the same selection rule to ordinary and distinct-streaming aggregation. Keep existing shuffled-consumer and multi-distinct behavior, and safely fall back to grouping expressions when the distribution field or outer list is missing or empty. The new bucket-key path does not select an empty inner list. - Keep actual grouping/deduplication keys, exchange types, bucket mappings and row-accounting checks unchanged. No FE, wire-format or storage-format changes are needed. - Add BE selector coverage and SQL regression coverage for three-/four-phase aggregation, streaming and local-shuffle switches, automatic phase selection, and duplicate input. ### Release note Fix local bucket-routing errors in affected multi-stage DISTINCT aggregations. ### Check List (For Author) - Test: BE unit tests and SQL regression tests added; local validation is listed below. - Behavior changed: Yes, affected bucket exchanges retain the input bucket key without changing aggregation semantics. - Does this need documentation: No. ### Validation Completed locally with ASAN BE/FE binaries: ```bash ./build.sh --be --fe -j48 ./run-be-ut.sh -j 48 --run --filter='AggOperatorRequiredDistributionTest.*:DistinctStreamingAggOperatorTest.*:LocalExchangerTest.*:PipelineTest.PLAN_LOCAL_EXCHANGE' ``` Build and FE checkstyle passed. All 17 selected BE unit tests passed. The following regression commands passed. `$REG_CONF` denotes the isolated local test-cluster configuration: ```bash ./run-regression-test.sh --conf "$REG_CONF" --run -d query_p0/aggregate -s test_bucket_route_multistage_distinct_repro -forceGenOut ./run-regression-test.sh --conf "$REG_CONF" --run -d query_p0/aggregate -s test_bucket_route_multistage_distinct_repro ./run-regression-test.sh --conf "$REG_CONF" --run -d pipeline_p0/local_shuffle -s test_bucket_hash_local_shuffle ./run-regression-test.sh --conf "$REG_CONF" --run -d nereids_syntax_p0 -s agg_4_phase ``` The new regression passed repeated non-generation runs, including a verification after the final commit. A three-BE validation with partial bucket ownership passed all 44 SQL executions. Eight complete, uncached profiles retained `BUCKET_HASH_SHUFFLE` with one partition expression, while grouping remained on both columns. Formatting and the committed-range whitespace check also passed. Not covered: cloud execution, mixed-version execution, spill, full unit/regression suites, or performance benchmarks. -- 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]
