This is an automated email from the ASF dual-hosted git repository.

jakevin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 92c6a3c53b [fix](Nereids) normalize repeat generate push down project 
with error nullable (#19831)
92c6a3c53b is described below

commit 92c6a3c53bd7b63e5fcfdccabaccee36347aae1a
Author: morrySnow <101034200+morrys...@users.noreply.github.com>
AuthorDate: Fri May 19 13:15:42 2023 +0800

    [fix](Nereids) normalize repeat generate push down project with error 
nullable (#19831)
---
 .../doris/nereids/rules/analysis/NormalizeRepeat.java |  8 --------
 .../nereids/rules/rewrite/logical/AdjustNullable.java | 19 +++++++++++++------
 2 files changed, 13 insertions(+), 14 deletions(-)

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<Expression> 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<NamedExpression> outputs = repeat.getOutputExpressions();
-
         Map<Expression, NormalizeToSlotTriplet> normalizeToSlotMap = 
Maps.newLinkedHashMap();
         for (Expression expression : sourceExpressions) {
             Optional<NormalizeToSlotTriplet> 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<Void> implements CustomR
     public Plan visitLogicalRepeat(LogicalRepeat<? extends Plan> repeat, Void 
context) {
         repeat = (LogicalRepeat<? extends Plan>) super.visit(repeat, context);
         Map<ExprId, Slot> exprIdSlotMap = collectChildrenOutputMap(repeat);
-        List<NamedExpression> newOutputs = 
updateExpressions(repeat.getOutputExpressions(), exprIdSlotMap);
-        List<List<Expression>> newGroupingSets = 
repeat.getGroupingSets().stream()
-                .map(l -> updateExpressions(l, exprIdSlotMap))
-                .collect(ImmutableList.toImmutableList());
-        return repeat.withGroupSetsAndOutput(newGroupingSets, 
newOutputs).recomputeLogicalProperties();
+        Set<Expression> flattenGroupingSetExpr = ImmutableSet.copyOf(
+                ExpressionUtils.flatExpressions(repeat.getGroupingSets()));
+        List<NamedExpression> 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<Void> implements CustomR
     }
 
     private <T extends Expression> T updateExpression(T input, Map<ExprId, 
Slot> exprIdSlotMap) {
-        return (T) input.rewriteDownShortCircuit(e -> 
SlotReferenceReplacer.INSTANCE.visit(e, exprIdSlotMap));
+        return (T) input.rewriteDownShortCircuit(e -> 
e.accept(SlotReferenceReplacer.INSTANCE, exprIdSlotMap));
     }
 
     private <T extends Expression> List<T> updateExpressions(List<T> inputs, 
Map<ExprId, Slot> exprIdSlotMap) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to