diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeRepeat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeRepeat.java index 2e979853ea..4efdd633d6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeRepeat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeRepeat.java @@ -226,17 +226,9 @@ public class NormalizeRepeat extends OneAnalysisRuleFactory { } List groupingSetExpressions = ExpressionUtils.flatExpressions(repeat.getGroupingSets()); - - // nullable will be different from grouping set and output expressions, - // so we can not use the slot in grouping set,but use the equivalent slot in output expressions. - List outputs = repeat.getOutputExpressions(); - Map normalizeToSlotMap = Maps.newLinkedHashMap(); for (Expression expression : sourceExpressions) { Optional pushDownTriplet; - if (expression instanceof NamedExpression && outputs.contains(expression)) { - expression = outputs.get(outputs.indexOf(expression)); - } if (groupingSetExpressions.contains(expression)) { pushDownTriplet = toGroupingSetExpressionPushDownTriplet(expression, existsAliasMap.get(expression)); } else { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/AdjustNullable.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/AdjustNullable.java index 55c5c2be08..abf7940caa 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/AdjustNullable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/AdjustNullable.java @@ -41,6 +41,7 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalTopN; import org.apache.doris.nereids.trees.plans.logical.LogicalWindow; import org.apache.doris.nereids.trees.plans.visitor.CustomRewriter; import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter; +import org.apache.doris.nereids.util.ExpressionUtils; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -116,11 +117,17 @@ public class AdjustNullable extends DefaultPlanRewriter implements CustomR public Plan visitLogicalRepeat(LogicalRepeat repeat, Void context) { repeat = (LogicalRepeat) super.visit(repeat, context); Map exprIdSlotMap = collectChildrenOutputMap(repeat); - List newOutputs = updateExpressions(repeat.getOutputExpressions(), exprIdSlotMap); - List> newGroupingSets = repeat.getGroupingSets().stream() - .map(l -> updateExpressions(l, exprIdSlotMap)) - .collect(ImmutableList.toImmutableList()); - return repeat.withGroupSetsAndOutput(newGroupingSets, newOutputs).recomputeLogicalProperties(); + Set flattenGroupingSetExpr = ImmutableSet.copyOf( + ExpressionUtils.flatExpressions(repeat.getGroupingSets())); + List newOutputs = Lists.newArrayList(); + for (NamedExpression output : repeat.getOutputExpressions()) { + if (flattenGroupingSetExpr.contains(output)) { + newOutputs.add(output); + } else { + newOutputs.add(updateExpression(output, exprIdSlotMap)); + } + } + return repeat.withGroupSetsAndOutput(repeat.getGroupingSets(), newOutputs).recomputeLogicalProperties(); } @Override @@ -178,7 +185,7 @@ public class AdjustNullable extends DefaultPlanRewriter implements CustomR } private T updateExpression(T input, Map exprIdSlotMap) { - return (T) input.rewriteDownShortCircuit(e -> SlotReferenceReplacer.INSTANCE.visit(e, exprIdSlotMap)); + return (T) input.rewriteDownShortCircuit(e -> e.accept(SlotReferenceReplacer.INSTANCE, exprIdSlotMap)); } private List updateExpressions(List inputs, Map exprIdSlotMap) {