[fix](Nereids): when child is Aggregate, don't infer Distinct for it (#21519)

This commit is contained in:
jakevin
2023-07-05 19:39:41 +08:00
committed by GitHub
parent 5d2739b5c5
commit b3db904847

View File

@ -50,7 +50,8 @@ public class InferSetOperatorDistinct extends OneRewriteRuleFactory {
}
List<Plan> newChildren = setOperation.children().stream()
.map(child -> new LogicalAggregate<>(ImmutableList.copyOf(child.getOutput()), true, child))
.map(child -> isAgg(child) ? child
: new LogicalAggregate<>(ImmutableList.copyOf(child.getOutput()), true, child))
.collect(ImmutableList.toImmutableList());
if (newChildren.equals(setOperation.children())) {
return null;
@ -59,6 +60,11 @@ public class InferSetOperatorDistinct extends OneRewriteRuleFactory {
}).toRule(RuleType.INFER_SET_OPERATOR_DISTINCT);
}
private boolean isAgg(Plan plan) {
return plan instanceof LogicalAggregate || (plan instanceof LogicalProject && plan.child(
0) instanceof LogicalAggregate);
}
// if children exist NLJ, we can't infer distinct
private boolean rejectNLJ(Plan plan) {
if (plan instanceof LogicalProject) {