diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java index e2aa4bb78c..aee951cb2a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java @@ -72,12 +72,12 @@ import org.apache.doris.planner.PlannerContext; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.apache.commons.lang.StringUtils; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -923,7 +923,7 @@ public class BindSlotReference implements AnalysisRuleFactory { .filter(ExpressionTrait::nullable) .collect(Collectors.toSet()); return projects.stream() - .map(e -> e.accept(new RewriteNullableToTrue(childrenOutput), null)) + .map(e -> e.accept(RewriteNullableToTrue.INSTANCE, childrenOutput)) .map(NamedExpression.class::cast) .collect(ImmutableList.toImmutableList()); } @@ -939,7 +939,7 @@ public class BindSlotReference implements AnalysisRuleFactory { .filter(ExpressionTrait::nullable) .collect(Collectors.toSet()); return output.stream() - .map(e -> e.accept(new RewriteNullableToTrue(childrenOutput), null)) + .map(e -> e.accept(RewriteNullableToTrue.INSTANCE, childrenOutput)) .map(NamedExpression.class::cast) .collect(ImmutableList.toImmutableList()); } @@ -951,24 +951,21 @@ public class BindSlotReference implements AnalysisRuleFactory { List> groupingSets, List output) { Set groupingSetsSlots = groupingSets.stream() - .flatMap(e -> e.stream()) - .flatMap(e -> e.>collect(SlotReference.class::isInstance).stream()) + .flatMap(Collection::stream) + .map(Expression::getInputSlots) + .flatMap(Set::stream) .collect(Collectors.toSet()); return output.stream() - .map(e -> e.accept(new RewriteNullableToTrue(groupingSetsSlots), null)) + .map(e -> e.accept(RewriteNullableToTrue.INSTANCE, groupingSetsSlots)) .map(NamedExpression.class::cast) .collect(ImmutableList.toImmutableList()); } - private static class RewriteNullableToTrue extends DefaultExpressionRewriter { - private final Set childrenOutput; - - public RewriteNullableToTrue(Set childrenOutput) { - this.childrenOutput = ImmutableSet.copyOf(childrenOutput); - } + private static class RewriteNullableToTrue extends DefaultExpressionRewriter> { + public static RewriteNullableToTrue INSTANCE = new RewriteNullableToTrue(); @Override - public Expression visitSlotReference(SlotReference slotReference, PlannerContext context) { + public Expression visitSlotReference(SlotReference slotReference, Set childrenOutput) { if (childrenOutput.contains(slotReference)) { return slotReference.withNullable(true); } 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 7738384ac4..c621176d48 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 @@ -223,7 +223,6 @@ public class NormalizeRepeat extends OneAnalysisRuleFactory { } List groupingSetExpressions = ExpressionUtils.flatExpressions(repeat.getGroupingSets()); - Set commonGroupingSetExpressions = repeat.getCommonGroupingSetExpressions(); // 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. @@ -236,9 +235,7 @@ public class NormalizeRepeat extends OneAnalysisRuleFactory { expression = outputs.get(outputs.indexOf(expression)); } if (groupingSetExpressions.contains(expression)) { - boolean isCommonGroupingSetExpression = commonGroupingSetExpressions.contains(expression); - pushDownTriplet = toGroupingSetExpressionPushDownTriplet( - isCommonGroupingSetExpression, expression, existsAliasMap.get(expression)); + pushDownTriplet = toGroupingSetExpressionPushDownTriplet(expression, existsAliasMap.get(expression)); } else { pushDownTriplet = Optional.of( NormalizeToSlotTriplet.toTriplet(expression, existsAliasMap.get(expression))); @@ -252,10 +249,10 @@ public class NormalizeRepeat extends OneAnalysisRuleFactory { } private Optional toGroupingSetExpressionPushDownTriplet( - boolean isCommonGroupingSetExpression, Expression expression, @Nullable Alias existsAlias) { + Expression expression, @Nullable Alias existsAlias) { NormalizeToSlotTriplet originTriplet = NormalizeToSlotTriplet.toTriplet(expression, existsAlias); SlotReference remainSlot = (SlotReference) originTriplet.remainExpr; - Slot newSlot = remainSlot.withCommonGroupingSetExpression(isCommonGroupingSetExpression); + Slot newSlot = remainSlot.withNullable(true); return Optional.of(new NormalizeToSlotTriplet(expression, newSlot, originTriplet.pushedExpr)); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/SlotReference.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/SlotReference.java index ee5feed16d..acc536a3df 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/SlotReference.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/SlotReference.java @@ -186,12 +186,4 @@ public class SlotReference extends Slot { public Slot withName(String name) { return new SlotReference(exprId, name, dataType, nullable, qualifier, column); } - - /** withCommonGroupingSetExpression */ - public Slot withCommonGroupingSetExpression(boolean isCommonGroupingSetExpression) { - if (!isCommonGroupingSetExpression) { - return withNullable(true); - } - return this; - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Repeat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Repeat.java index 7b937943a1..267e60c629 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Repeat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Repeat.java @@ -76,7 +76,6 @@ public interface Repeat extends Aggregate { */ default Set getCommonGroupingSetExpressions() { List> groupingSets = getGroupingSets(); - Sets.newLinkedHashSet(); Iterator> iterator = groupingSets.iterator(); Set commonGroupingExpressions = Sets.newLinkedHashSet(iterator.next()); while (iterator.hasNext()) {