OIiveirra commented on code in PR #71331:
URL: https://github.com/apache/doris/pull/71331#discussion_r4780730703


##########
fe/fe-core/src/test/java/org/apache/doris/planner/LocalShuffleNodeCoverageTest.java:
##########
@@ -1119,6 +1125,135 @@ public void 
testAggregationNodeInheritedShuffleUsesChildDistributeExprs() {
                 "the grouping key must not replace the inherited child 
distribution key");
     }
 
+    /** Build the file scan -> local SUM fragment after the group slots have 
been renumbered. */
+    private static class FilePartialAggregatePlan {
+        final SessionVariable session = new SessionVariable();
+        final PlanTranslatorContext ctx = Mockito.spy(new 
PlanTranslatorContext());
+        final AggregateInfo info = Mockito.mock(AggregateInfo.class);
+        final FunctionCallExpr sum = plainAggregateFunction("sum");
+        final TupleDescriptor input = new TupleDescriptor(new TupleId(19));
+        final TupleDescriptor output = new TupleDescriptor(new TupleId(71));
+        final SlotRef inputKey = addStringSlot(input, 93);
+        final SlotRef inputStatus = addStringSlot(input, 101);
+        final SlotRef outputKey = addStringSlot(output, 14);
+        final SlotRef outputStatus = addStringSlot(output, 32);
+        final AggregationNode agg;
+        final FileQueryScanNode scan;
+        final DataStreamSink sink = new DataStreamSink(nextPlanNodeId());
+        final PlanFragment fragment;
+
+        FilePartialAggregatePlan() {
+            ConnectContext connect = Mockito.mock(ConnectContext.class);
+            Mockito.when(connect.getSessionVariable()).thenReturn(session);
+            Mockito.doReturn(connect).when(ctx).getConnectContext();
+            ctx.setCurrentFragmentMinInstancesPerBe(4);
+
+            scan = Mockito.mock(FileQueryScanNode.class, Mockito.withSettings()
+                    .useConstructor(nextPlanNodeId(), input, "FILE_SCAN", 
ScanContext.EMPTY, false, session)
+                    .defaultAnswer(Mockito.CALLS_REAL_METHODS));
+            Mockito.doReturn(true).when(scan).isSerialNode();
+            Mockito.doReturn(true).when(scan).isSerialOperatorOnBe(connect);
+
+            AggregateFunction fn = Mockito.mock(AggregateFunction.class);
+            
Mockito.when(fn.getBinaryType()).thenReturn(Function.BinaryType.BUILTIN);
+            Mockito.when(sum.getFn()).thenReturn(fn);
+            Mockito.when(sum.getParams()).thenReturn(new FunctionParams(false, 
Collections.emptyList()));
+            Mockito.when(info.getOutputTupleId()).thenReturn(output.getId());
+            Mockito.when(info.getOutputTupleDesc()).thenReturn(output);
+            Mockito.when(info.isFirstPhase()).thenReturn(true);
+            
Mockito.when(info.getGroupingExprs()).thenReturn(Lists.newArrayList(inputKey, 
inputStatus));
+            
Mockito.when(info.getAggregateExprs()).thenReturn(Lists.newArrayList(sum));
+            agg = new AggregationNode(nextPlanNodeId(), scan, info);
+            agg.unsetNeedsFinalize();
+            agg.setUseStreamingPreagg(true);
+            agg.setEstimatedGroupsForLocalExchange(4);
+            fragment = new PlanFragment(new PlanFragmentId(5), agg, 
DataPartition.RANDOM);
+            fragment.setSink(sink);
+            partitionBy(outputKey, outputStatus);
+        }
+
+        private static SlotRef addStringSlot(TupleDescriptor tuple, int 
slotId) {
+            SlotDescriptor slot = new SlotDescriptor(new SlotId(slotId), 
tuple.getId());
+            slot.setType(Type.STRING);
+            tuple.addSlot(slot);
+            return new SlotRef(slot);
+        }
+
+        void partitionBy(Expr first, Expr second) {
+            DataPartition partition = new 
DataPartition(TPartitionType.HASH_PARTITIONED,
+                    Lists.newArrayList(first, second));
+            fragment.setOutputPartition(partition);
+            sink.setOutputPartition(partition);
+        }
+
+        void assertExchange(LocalExchangeType expected) {
+            agg.enforceAndDeriveLocalExchange(ctx, null, 
LocalExchangeTypeRequire.noRequire());
+            assertChildLocalExchangeType(agg, 0, expected);
+        }
+    }
+
+    @Test
+    public void testLowCardinalityFilePartialAggregateUsesPassthrough() {
+        new 
FilePartialAggregatePlan().assertExchange(LocalExchangeType.PASSTHROUGH);

Review Comment:
   Added and ran the Iceberg regression in a2651acdf8b. It analyzes a 
131,072-row table with repeated groups across four inserts, checks the exchange 
directly below partial aggregation in both distributed plans, and compares the 
ordered SUM, AVG and COUNT results with the same four expected rows. Both the 
passthrough and forced local-hash paths passed.



-- 
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]

Reply via email to