Skip to content

Commit

Permalink
[fix](Nereids): TransposeSemiJoinAgg can't apply in Scalar Agg (apach…
Browse files Browse the repository at this point in the history
…e#28434)

Scalar Agg shouldn't be pushdown, it will cause wrong result
  • Loading branch information
jackwener authored Dec 15, 2023
1 parent 8986bb6 commit 0f93ee8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public Rule build() {
public static boolean canTranspose(LogicalAggregate<? extends Plan> aggregate,
LogicalJoin<? extends Plan, ? extends Plan> join) {
Set<Slot> canPushDownSlots = PushDownFilterThroughAggregation.getCanPushDownSlots(aggregate);
// avoid push down scalar agg.
if (canPushDownSlots.isEmpty()) {
return false;
}
Set<Slot> leftConditionSlot = join.getLeftConditionSlot();
return canPushDownSlots.containsAll(leftConditionSlot);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.nereids.rules.rewrite;

import org.apache.doris.common.Pair;
import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
import org.apache.doris.nereids.trees.plans.JoinType;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
Expand Down Expand Up @@ -49,4 +50,15 @@ void simple() {
);
}

@Test
void rejectScalarAgg() {
LogicalPlan plan = new LogicalPlanBuilder(scan1)
.agg(ImmutableList.of(), ImmutableList.of((new Sum(scan1.getOutput().get(0))).alias("sum")))
.join(scan2, JoinType.LEFT_SEMI_JOIN, Pair.of(0, 0))
.build();
PlanChecker.from(MemoTestUtils.createConnectContext(), plan)
.applyTopDown(new TransposeSemiJoinAgg())
.matchesFromRoot(leftSemiLogicalJoin(logicalAggregate(), logicalOlapScan()));
}

}

0 comments on commit 0f93ee8

Please sign in to comment.