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 @@ -2230,9 +2230,11 @@ public PlanFragment visitPhysicalRepeat(PhysicalRepeat<? extends Plan> repeat, P
.map(expr -> ExpressionTranslator.translate(expr, context)).collect(ImmutableList.toImmutableList());

// outputSlots's order need same with preRepeatExprs
List<Slot> outputSlots = Stream.concat(
repeat.getOutputExpressions().stream().filter(output -> flattenGroupingSetExprs.contains(output)),
repeat.getOutputExpressions().stream().filter(output -> !flattenGroupingSetExprs.contains(output)))
List<Slot> outputSlots = Stream
.concat(repeat.getOutputExpressions().stream()
.filter(output -> flattenGroupingSetExprs.contains(output)),
repeat.getOutputExpressions().stream()
.filter(output -> !flattenGroupingSetExprs.contains(output)).distinct())
.map(NamedExpression::toSlot).collect(ImmutableList.toImmutableList());

// NOTE: we should first translate preRepeatExprs, then generate output tuple,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ private Plan bindRepeat(MatchingContext<LogicalRepeat<Plan>> ctx) {
boundGroupingSetsBuilder.add(boundGroupingSet);
}
List<List<Expression>> boundGroupingSets = boundGroupingSetsBuilder.build();
List<NamedExpression> nullableOutput = adjustNullableForRepeat(boundGroupingSets, boundRepeatOutput);
List<NamedExpression> nullableOutput = PlanUtils.adjustNullableForRepeat(boundGroupingSets, boundRepeatOutput);
for (List<Expression> groupingSet : boundGroupingSets) {
checkIfOutputAliasNameDuplicatedForGroupBy(groupingSet, nullableOutput);
}
Expand Down Expand Up @@ -803,30 +803,6 @@ private Plan bindSortWithoutSetOperation(MatchingContext<LogicalSort<Plan>> ctx)
return new LogicalSort<>(boundOrderKeys.build(), sort.child());
}

/**
* For the columns whose output exists in grouping sets, they need to be assigned as nullable.
*/
private List<NamedExpression> adjustNullableForRepeat(
List<List<Expression>> groupingSets,
List<NamedExpression> outputs) {
Set<Slot> groupingSetsUsedSlots = groupingSets.stream()
.flatMap(Collection::stream)
.map(Expression::getInputSlots)
.flatMap(Set::stream)
.collect(Collectors.toSet());
Builder<NamedExpression> nullableOutputs = ImmutableList.builderWithExpectedSize(outputs.size());
for (NamedExpression output : outputs) {
Expression nullableOutput = output.rewriteUp(expr -> {
if (expr instanceof Slot && groupingSetsUsedSlots.contains(expr)) {
return ((Slot) expr).withNullable(true);
}
return expr;
});
nullableOutputs.add((NamedExpression) nullableOutput);
}
return nullableOutputs.build();
}

private LogicalTVFRelation bindTableValuedFunction(MatchingContext<UnboundTVFRelation> ctx) {
UnboundTVFRelation unboundTVFRelation = ctx.root;
StatementContext statementContext = ctx.statementContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.apache.doris.nereids.trees.plans.logical.LogicalRepeat;
import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanVisitor;
import org.apache.doris.nereids.util.ExpressionUtils;
import org.apache.doris.nereids.util.PlanUtils;
import org.apache.doris.planner.PlanNode;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -580,20 +581,20 @@ public LogicalAggregate<Plan> visitLogicalAggregate(LogicalAggregate<? extends P
public LogicalRepeat<Plan> visitLogicalRepeat(LogicalRepeat<? extends Plan> repeat, Void ctx) {
Plan child = repeat.child(0).accept(this, ctx);
List<List<Expression>> groupingSets = repeat.getGroupingSets();
ImmutableList.Builder<List<Expression>> newGroupingExprs = ImmutableList.builder();
List<List<Expression>> newGroupingExprs = Lists.newArrayList();
for (List<Expression> expressions : groupingSets) {
newGroupingExprs.add(expressions.stream()
.map(expr -> new ReplaceExpressionWithMvColumn(slotContext).replace(expr))
.collect(ImmutableList.toImmutableList())
);
newGroupingExprs.add(
expressions.stream().map(expr -> new ReplaceExpressionWithMvColumn(slotContext).replace(expr))
.collect(ImmutableList.toImmutableList()));
}

List<NamedExpression> outputExpressions = repeat.getOutputExpressions();
List<NamedExpression> newOutputExpressions = outputExpressions.stream()
.map(expr -> (NamedExpression) new ReplaceExpressionWithMvColumn(slotContext).replace(expr))
.collect(ImmutableList.toImmutableList());
List<NamedExpression> newOutputExpressions = PlanUtils.adjustNullableForRepeat(newGroupingExprs,
outputExpressions.stream()
.map(expr -> (NamedExpression) new ReplaceExpressionWithMvColumn(slotContext).replace(expr))
.collect(ImmutableList.toImmutableList()));

return repeat.withNormalizedExpr(newGroupingExprs.build(), newOutputExpressions, child);
return repeat.withNormalizedExpr(newGroupingExprs, newOutputExpressions, child);
}

@Override
Expand Down
Loading