Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import org.apache.doris.nereids.trees.expressions.NamedExpression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateParam;
import org.apache.doris.nereids.trees.expressions.functions.agg.NullableAggregateFunction;
import org.apache.doris.nereids.trees.plans.AggMode;
import org.apache.doris.nereids.trees.plans.AggPhase;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.algebra.Aggregate;
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
import org.apache.doris.nereids.util.ExpressionUtils;
import org.apache.doris.nereids.util.MutableState;
import org.apache.doris.nereids.util.Utils;
import org.apache.doris.statistics.Statistics;
Expand Down Expand Up @@ -93,8 +95,9 @@ public PhysicalHashAggregate(List<Expression> groupByExpressions, List<NamedExpr
super(PlanType.PHYSICAL_HASH_AGGREGATE, groupExpression, logicalProperties, child);
this.groupByExpressions = ImmutableList.copyOf(
Objects.requireNonNull(groupByExpressions, "groupByExpressions cannot be null"));
this.outputExpressions = ImmutableList.copyOf(
Objects.requireNonNull(outputExpressions, "outputExpressions cannot be null"));
this.outputExpressions = adjustNullableForOutputs(
Objects.requireNonNull(outputExpressions, "outputExpressions cannot be null"),
groupByExpressions.isEmpty());
this.partitionExpressions = Objects.requireNonNull(
partitionExpressions, "partitionExpressions cannot be null");
this.aggregateParam = Objects.requireNonNull(aggregateParam, "aggregate param cannot be null");
Expand All @@ -120,8 +123,9 @@ public PhysicalHashAggregate(List<Expression> groupByExpressions, List<NamedExpr
child);
this.groupByExpressions = ImmutableList.copyOf(
Objects.requireNonNull(groupByExpressions, "groupByExpressions cannot be null"));
this.outputExpressions = ImmutableList.copyOf(
Objects.requireNonNull(outputExpressions, "outputExpressions cannot be null"));
this.outputExpressions = adjustNullableForOutputs(
Objects.requireNonNull(outputExpressions, "outputExpressions cannot be null"),
groupByExpressions.isEmpty());
this.partitionExpressions = Objects.requireNonNull(
partitionExpressions, "partitionExpressions cannot be null");
this.aggregateParam = Objects.requireNonNull(aggregateParam, "aggregate param cannot be null");
Expand Down Expand Up @@ -330,4 +334,15 @@ public PhysicalHashAggregate<CHILD_TYPE> setTopnPushInfo(TopnPushInfo topnPushIn
setMutableState(MutableState.KEY_PUSH_TOPN_TO_AGG, topnPushInfo);
return this;
}

private List<NamedExpression> adjustNullableForOutputs(List<NamedExpression> outputs, boolean alwaysNullable) {
return ExpressionUtils.rewriteDownShortCircuit(outputs, output -> {
if (output instanceof NullableAggregateFunction
&& ((NullableAggregateFunction) output).isAlwaysNullable() != alwaysNullable) {
return ((NullableAggregateFunction) output).withAlwaysNullable(alwaysNullable);
} else {
return output;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void globalAggregate() {
Plan root = new LogicalAggregate<>(groupExpressionList, outputExpressionList,
true, Optional.empty(), rStudent);

Sum localOutput0 = new Sum(rStudent.getOutput().get(0).toSlot());
Sum localOutput0 = new Sum(false, true, rStudent.getOutput().get(0).toSlot());

PlanChecker.from(MemoTestUtils.createConnectContext(), root)
.applyImplementation(twoPhaseAggregateWithoutDistinct())
Expand Down