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

morrysnow 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 75d7de89a5 [improve](Nereids) Add all slots used by onClause to 
project when reorder and fix reorder mark (#12701)
75d7de89a5 is described below

commit 75d7de89a56e4eca9c1831a887e38b4683208235
Author: jakevin <jakevin...@gmail.com>
AuthorDate: Mon Sep 19 11:01:25 2022 +0800

    [improve](Nereids) Add all slots used by onClause to project when reorder 
and fix reorder mark (#12701)
    
    1. Add all slots used by onClause in project
    
    ```
    (A & B) & C like
    join(hash conjuncts: C.t2 = A.t2)
    |---project(A.t2)
    |   +---join(hash conjuncts: A.t1 = B.t1)
    |       +---A
    |       +---B
    +---C
    
    transform to (A & C) & B
    join(hash conjuncts: A.t1 = B.t1)
    |---project(A.t2)
    |   +---join(hash conjuncts: C.t2 = A.t2)
    |       +---A
    |       +---C
    +---B
    ```
    
    But projection just include `A.t2`, can't find `A.t1`, we should add slots 
used by onClause when projection exist.
    
    2. fix join reorder mark
    
    Add mark `LAsscom` when apply `LAsscom`
    
    3. remove slotReference
    
    use `Slot` instead of `SlotReference` to avoid cast.
---
 .../rules/exploration/join/InnerJoinLAsscom.java   | 11 +++-
 .../exploration/join/InnerJoinLAsscomProject.java  |  4 +-
 .../rules/exploration/join/JoinCommuteHelper.java  |  7 +--
 .../rules/exploration/join/JoinLAsscomHelper.java  | 70 ++++++++++------------
 .../rules/exploration/join/OuterJoinLAsscom.java   | 21 +++++--
 .../exploration/join/OuterJoinLAsscomProject.java  |  4 +-
 .../rules/exploration/join/ThreeJoinHelper.java    | 31 +++++-----
 .../LogicalOlapScanToPhysicalOlapScan.java         |  5 +-
 .../org/apache/doris/nereids/util/JoinUtils.java   | 43 +++++++------
 .../java/org/apache/doris/nereids/util/Utils.java  | 10 ----
 10 files changed, 103 insertions(+), 103 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscom.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscom.java
index 9286ba33f7..021987cb7d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscom.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscom.java
@@ -20,6 +20,9 @@ package org.apache.doris.nereids.rules.exploration.join;
 import org.apache.doris.nereids.rules.Rule;
 import org.apache.doris.nereids.rules.RuleType;
 import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory;
+import org.apache.doris.nereids.trees.plans.GroupPlan;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
 
 /**
  * Rule for change inner join LAsscom (associative and commutive).
@@ -37,7 +40,7 @@ public class InnerJoinLAsscom extends 
OneExplorationRuleFactory {
     @Override
     public Rule build() {
         return innerLogicalJoin(innerLogicalJoin(), group())
-                .when(topJoin -> JoinLAsscomHelper.checkInner(topJoin, 
topJoin.left()))
+                .when(topJoin -> check(topJoin, topJoin.left()))
                 .then(topJoin -> {
                     JoinLAsscomHelper helper = new JoinLAsscomHelper(topJoin, 
topJoin.left());
                     if (!helper.initJoinOnCondition()) {
@@ -46,4 +49,10 @@ public class InnerJoinLAsscom extends 
OneExplorationRuleFactory {
                     return helper.newTopJoin();
                 }).toRule(RuleType.LOGICAL_INNER_JOIN_LASSCOM);
     }
+
+    public static boolean check(LogicalJoin<? extends Plan, GroupPlan> topJoin,
+            LogicalJoin<GroupPlan, GroupPlan> bottomJoin) {
+        return !bottomJoin.getJoinReorderContext().hasCommuteZigZag()
+                && !topJoin.getJoinReorderContext().hasLAsscom();
+    }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
index 50e4858b72..7f3fc20c68 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/InnerJoinLAsscomProject.java
@@ -39,10 +39,10 @@ public class InnerJoinLAsscomProject extends 
OneExplorationRuleFactory {
     @Override
     public Rule build() {
         return innerLogicalJoin(logicalProject(innerLogicalJoin()), group())
-                .when(topJoin -> JoinLAsscomHelper.checkInner(topJoin, 
topJoin.left().child()))
+                .when(topJoin -> InnerJoinLAsscom.check(topJoin, 
topJoin.left().child()))
                 .then(topJoin -> {
                     JoinLAsscomHelper helper = new JoinLAsscomHelper(topJoin, 
topJoin.left().child());
-                    helper.initAllProject(topJoin.left());
+                    helper.initProject(topJoin.left());
                     if (!helper.initJoinOnCondition()) {
                         return null;
                     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommuteHelper.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommuteHelper.java
index 288c566a72..cb07f2383c 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommuteHelper.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommuteHelper.java
@@ -17,10 +17,9 @@
 
 package org.apache.doris.nereids.rules.exploration.join;
 
-import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.plans.GroupPlan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
-import org.apache.doris.nereids.util.Utils;
 
 import java.util.List;
 
@@ -47,7 +46,7 @@ class JoinCommuteHelper {
 
     private static boolean containJoin(GroupPlan groupPlan) {
         // TODO: tmp way to judge containJoin
-        List<SlotReference> output = Utils.getOutputSlotReference(groupPlan);
-        return 
!output.stream().map(SlotReference::getQualifier).allMatch(output.get(0).getQualifier()::equals);
+        List<Slot> output = groupPlan.getOutput();
+        return 
!output.stream().map(Slot::getQualifier).allMatch(output.get(0).getQualifier()::equals);
     }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinLAsscomHelper.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinLAsscomHelper.java
index 20e05f96f8..74bf081090 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinLAsscomHelper.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinLAsscomHelper.java
@@ -19,15 +19,14 @@ package org.apache.doris.nereids.rules.exploration.join;
 
 import org.apache.doris.nereids.trees.expressions.NamedExpression;
 import org.apache.doris.nereids.trees.expressions.Slot;
-import org.apache.doris.nereids.trees.expressions.SlotReference;
 import org.apache.doris.nereids.trees.plans.GroupPlan;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
 import org.apache.doris.nereids.util.ExpressionUtils;
 import org.apache.doris.nereids.util.PlanUtils;
-import org.apache.doris.nereids.util.Utils;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -57,35 +56,30 @@ class JoinLAsscomHelper extends ThreeJoinHelper {
      * Create newTopJoin.
      */
     public Plan newTopJoin() {
-        // Split inside-project into two part.
-        Map<Boolean, List<NamedExpression>> projectExprsMap = 
allProjects.stream()
+        // Split bottomJoinProject into two part.
+        Map<Boolean, List<NamedExpression>> projectExprsMap = 
bottomProjects.stream()
                 .collect(Collectors.partitioningBy(projectExpr -> {
                     Set<Slot> usedSlots = 
projectExpr.collect(Slot.class::isInstance);
-                    return bOutput.containsAll(usedSlots);
+                    return bOutputSet.containsAll(usedSlots);
                 }));
+        List<NamedExpression> newLeftProjects = 
projectExprsMap.get(Boolean.FALSE);
+        List<NamedExpression> newRightProjects = 
projectExprsMap.get(Boolean.TRUE);
 
-        List<NamedExpression> newLeftProjectExpr = 
projectExprsMap.get(Boolean.FALSE);
-        List<NamedExpression> newRightProjectExprs = 
projectExprsMap.get(Boolean.TRUE);
-
-        // If add project to B, we should add all slotReference used by 
hashOnCondition.
+        // Add all slots used by hashOnCondition when projects not empty.
         // TODO: Does nonHashOnCondition also need to be considered.
-        Set<SlotReference> onUsedSlotRef = 
bottomJoin.getHashJoinConjuncts().stream()
-                .flatMap(expr -> {
-                    Set<SlotReference> usedSlotRefs = 
expr.collect(SlotReference.class::isInstance);
+        Map<Boolean, List<Slot>> onUsedSlots = 
bottomJoin.getHashJoinConjuncts().stream()
+                .flatMap(onExpr -> {
+                    Set<Slot> usedSlotRefs = 
onExpr.collect(Slot.class::isInstance);
                     return usedSlotRefs.stream();
-                
}).filter(Utils.getOutputSlotReference(bottomJoin)::contains).collect(Collectors.toSet());
-        boolean existRightProject = !newRightProjectExprs.isEmpty();
-        boolean existLeftProject = !newLeftProjectExpr.isEmpty();
-        onUsedSlotRef.forEach(slotRef -> {
-            if (existRightProject && bOutput.contains(slotRef) && 
!newRightProjectExprs.contains(slotRef)) {
-                newRightProjectExprs.add(slotRef);
-            } else if (existLeftProject && aOutput.contains(slotRef) && 
!newLeftProjectExpr.contains(slotRef)) {
-                newLeftProjectExpr.add(slotRef);
-            }
-        });
+                }).collect(Collectors.partitioningBy(bOutputSet::contains));
+        List<Slot> leftUsedSlots = onUsedSlots.get(Boolean.FALSE);
+        List<Slot> rightUsedSlots = onUsedSlots.get(Boolean.TRUE);
 
-        if (existLeftProject) {
-            newLeftProjectExpr.addAll(cOutput);
+        addSlotsUsedByOn(rightUsedSlots, newRightProjects);
+        addSlotsUsedByOn(leftUsedSlots, newLeftProjects);
+
+        if (!newLeftProjects.isEmpty()) {
+            newLeftProjects.addAll(cOutputSet);
         }
         LogicalJoin<GroupPlan, GroupPlan> newBottomJoin = new 
LogicalJoin<>(topJoin.getJoinType(),
                 newBottomHashJoinConjuncts, 
ExpressionUtils.optionalAnd(newBottomNonHashJoinConjuncts), a, c,
@@ -93,8 +87,8 @@ class JoinLAsscomHelper extends ThreeJoinHelper {
         newBottomJoin.getJoinReorderContext().setHasLAsscom(false);
         newBottomJoin.getJoinReorderContext().setHasCommute(false);
 
-        Plan left = PlanUtils.projectOrSelf(newLeftProjectExpr, newBottomJoin);
-        Plan right = PlanUtils.projectOrSelf(newRightProjectExprs, b);
+        Plan left = PlanUtils.projectOrSelf(newLeftProjects, newBottomJoin);
+        Plan right = PlanUtils.projectOrSelf(newRightProjects, b);
 
         LogicalJoin<Plan, Plan> newTopJoin = new 
LogicalJoin<>(bottomJoin.getJoinType(),
                 newTopHashJoinConjuncts,
@@ -105,18 +99,16 @@ class JoinLAsscomHelper extends ThreeJoinHelper {
         return PlanUtils.projectOrSelf(new ArrayList<>(topJoin.getOutput()), 
newTopJoin);
     }
 
-    public static boolean checkInner(LogicalJoin<? extends Plan, GroupPlan> 
topJoin,
-            LogicalJoin<GroupPlan, GroupPlan> bottomJoin) {
-        return !bottomJoin.getJoinReorderContext().hasCommuteZigZag()
-                && !topJoin.getJoinReorderContext().hasLAsscom();
-    }
-
-    public static boolean checkOuter(LogicalJoin<? extends Plan, GroupPlan> 
topJoin,
-            LogicalJoin<GroupPlan, GroupPlan> bottomJoin) {
-        // hasCommute will cause to lack of OuterJoinAssocRule:Left
-        return !topJoin.getJoinReorderContext().hasLeftAssociate()
-                && !topJoin.getJoinReorderContext().hasRightAssociate()
-                && !topJoin.getJoinReorderContext().hasExchange()
-                && !bottomJoin.getJoinReorderContext().hasCommute();
+    // When project not empty, we add all slots used by hashOnCondition into 
projects.
+    private void addSlotsUsedByOn(List<Slot> usedSlots, List<NamedExpression> 
projects) {
+        if (projects.isEmpty()) {
+            return;
+        }
+        Set<NamedExpression> projectsSet = new HashSet<>(projects);
+        usedSlots.forEach(slot -> {
+            if (!projectsSet.contains(slot)) {
+                projects.add(slot);
+            }
+        });
     }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscom.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscom.java
index 8672c9cc89..70b451a910 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscom.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscom.java
@@ -21,7 +21,10 @@ import org.apache.doris.common.Pair;
 import org.apache.doris.nereids.rules.Rule;
 import org.apache.doris.nereids.rules.RuleType;
 import org.apache.doris.nereids.rules.exploration.OneExplorationRuleFactory;
+import org.apache.doris.nereids.trees.plans.GroupPlan;
 import org.apache.doris.nereids.trees.plans.JoinType;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
 
 import com.google.common.collect.ImmutableSet;
 
@@ -50,14 +53,24 @@ public class OuterJoinLAsscom extends 
OneExplorationRuleFactory {
     @Override
     public Rule build() {
         return logicalJoin(logicalJoin(), group())
-                .when(topJoin -> JoinLAsscomHelper.checkOuter(topJoin, 
topJoin.left()))
+                .when(topJoin -> check(topJoin, topJoin.left()))
                 .when(join -> 
VALID_TYPE_PAIR_SET.contains(Pair.of(join.left().getJoinType(), 
join.getJoinType())))
                 .then(topJoin -> {
                     JoinLAsscomHelper helper = new JoinLAsscomHelper(topJoin, 
topJoin.left());
-                    if (!helper.initJoinOnCondition()) {
-                        return null;
-                    }
                     return helper.newTopJoin();
                 }).toRule(RuleType.LOGICAL_OUTER_JOIN_LASSCOM);
     }
+
+    /**
+     * check.
+     */
+    public static boolean check(LogicalJoin<? extends Plan, GroupPlan> topJoin,
+            LogicalJoin<GroupPlan, GroupPlan> bottomJoin) {
+        // hasCommute will cause to lack of OuterJoinAssocRule:Left
+        return !topJoin.getJoinReorderContext().hasLAsscom()
+                && !topJoin.getJoinReorderContext().hasLeftAssociate()
+                && !topJoin.getJoinReorderContext().hasRightAssociate()
+                && !topJoin.getJoinReorderContext().hasExchange()
+                && !bottomJoin.getJoinReorderContext().hasCommute();
+    }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
index 65a9421e9f..6cda79c3b7 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/OuterJoinLAsscomProject.java
@@ -40,12 +40,12 @@ public class OuterJoinLAsscomProject extends 
OneExplorationRuleFactory {
     @Override
     public Rule build() {
         return logicalJoin(logicalProject(logicalJoin()), group())
-                .when(topJoin -> JoinLAsscomHelper.checkOuter(topJoin, 
topJoin.left().child()))
+                .when(topJoin -> OuterJoinLAsscom.check(topJoin, 
topJoin.left().child()))
                 .when(join -> OuterJoinLAsscom.VALID_TYPE_PAIR_SET.contains(
                         Pair.of(join.left().child().getJoinType(), 
join.getJoinType())))
                 .then(topJoin -> {
                     JoinLAsscomHelper helper = new JoinLAsscomHelper(topJoin, 
topJoin.left().child());
-                    helper.initAllProject(topJoin.left());
+                    helper.initProject(topJoin.left());
                     if (!helper.initJoinOnCondition()) {
                         return null;
                     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/ThreeJoinHelper.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/ThreeJoinHelper.java
index e93aa5f104..fd305813cd 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/ThreeJoinHelper.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/ThreeJoinHelper.java
@@ -44,11 +44,12 @@ abstract class ThreeJoinHelper {
     protected final GroupPlan b;
     protected final GroupPlan c;
 
-    protected final Set<Slot> aOutput;
-    protected final Set<Slot> bOutput;
-    protected final Set<Slot> cOutput;
+    protected final Set<Slot> aOutputSet;
+    protected final Set<Slot> bOutputSet;
+    protected final Set<Slot> cOutputSet;
+    protected final Set<Slot> bottomJoinOutputSet;
 
-    protected final List<NamedExpression> allProjects = Lists.newArrayList();
+    protected final List<NamedExpression> bottomProjects = 
Lists.newArrayList();
 
     protected final List<Expression> allHashJoinConjuncts = 
Lists.newArrayList();
     protected final List<Expression> allNonHashJoinConjuncts = 
Lists.newArrayList();
@@ -70,9 +71,10 @@ abstract class ThreeJoinHelper {
         this.b = b;
         this.c = c;
 
-        aOutput = a.getOutputSet();
-        bOutput = b.getOutputSet();
-        cOutput = c.getOutputSet();
+        aOutputSet = a.getOutputSet();
+        bOutputSet = b.getOutputSet();
+        cOutputSet = c.getOutputSet();
+        bottomJoinOutputSet = bottomJoin.getOutputSet();
 
         Preconditions.checkArgument(!topJoin.getHashJoinConjuncts().isEmpty(), 
"topJoin hashJoinConjuncts must exist.");
         
Preconditions.checkArgument(!bottomJoin.getHashJoinConjuncts().isEmpty(),
@@ -86,11 +88,8 @@ abstract class ThreeJoinHelper {
                 ExpressionUtils.extractConjunction(otherJoinCondition)));
     }
 
-    @SafeVarargs
-    public final void initAllProject(LogicalProject<? extends Plan>... 
projects) {
-        for (LogicalProject<? extends Plan> project : projects) {
-            allProjects.addAll(project.getProjects());
-        }
+    public final void initProject(LogicalProject<? extends Plan> project) {
+        bottomProjects.addAll(project.getProjects());
     }
 
     /**
@@ -102,14 +101,14 @@ abstract class ThreeJoinHelper {
         // TODO: also need for otherJoinCondition
         for (Expression topJoinOnClauseConjunct : 
topJoin.getHashJoinConjuncts()) {
             Set<Slot> topJoinUsedSlot = 
topJoinOnClauseConjunct.collect(SlotReference.class::isInstance);
-            if (ExpressionUtils.isIntersecting(topJoinUsedSlot, aOutput) && 
ExpressionUtils.isIntersecting(
-                    topJoinUsedSlot, bOutput) && 
ExpressionUtils.isIntersecting(topJoinUsedSlot, cOutput)) {
+            if (ExpressionUtils.isIntersecting(topJoinUsedSlot, aOutputSet) && 
ExpressionUtils.isIntersecting(
+                    topJoinUsedSlot, bOutputSet) && 
ExpressionUtils.isIntersecting(topJoinUsedSlot, cOutputSet)) {
                 return false;
             }
         }
 
-        Set<Slot> newBottomJoinSlots = new HashSet<>(aOutput);
-        newBottomJoinSlots.addAll(cOutput);
+        Set<Slot> newBottomJoinSlots = new HashSet<>(aOutputSet);
+        newBottomJoinSlots.addAll(cOutputSet);
         for (Expression hashConjunct : allHashJoinConjuncts) {
             Set<SlotReference> slots = 
hashConjunct.collect(SlotReference.class::isInstance);
             if (newBottomJoinSlots.containsAll(slots)) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java
index 83f5ce6c1e..3ebaa3eab2 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java
@@ -27,10 +27,9 @@ import 
org.apache.doris.nereids.properties.DistributionSpecHash.ShuffleType;
 import org.apache.doris.nereids.rules.Rule;
 import org.apache.doris.nereids.rules.RuleType;
 import org.apache.doris.nereids.trees.expressions.ExprId;
-import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapScan;
-import org.apache.doris.nereids.util.Utils;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -63,7 +62,7 @@ public class LogicalOlapScanToPhysicalOlapScan extends 
OneImplementationRuleFact
         if (distributionInfo instanceof HashDistributionInfo) {
             HashDistributionInfo hashDistributionInfo = (HashDistributionInfo) 
distributionInfo;
 
-            List<SlotReference> output = 
Utils.getOutputSlotReference(olapScan);
+            List<Slot> output = olapScan.getOutput();
             List<ExprId> hashColumns = Lists.newArrayList();
             List<Column> schemaColumns = olapScan.getTable().getFullSchema();
             for (int i = 0; i < schemaColumns.size(); i++) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java
index b17a176148..c7e6d4e978 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java
@@ -26,7 +26,6 @@ import org.apache.doris.nereids.trees.expressions.EqualTo;
 import org.apache.doris.nereids.trees.expressions.ExprId;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import org.apache.doris.nereids.trees.expressions.Slot;
-import org.apache.doris.nereids.trees.expressions.SlotReference;
 import org.apache.doris.nereids.trees.plans.JoinType;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.algebra.Join;
@@ -62,20 +61,20 @@ public class JoinUtils {
         Set<ExprId> leftExprIds;
         Set<ExprId> rightExprIds;
 
-        JoinSlotCoverageChecker(List<SlotReference> left, List<SlotReference> 
right) {
-            leftExprIds = 
left.stream().map(SlotReference::getExprId).collect(Collectors.toSet());
-            rightExprIds = 
right.stream().map(SlotReference::getExprId).collect(Collectors.toSet());
+        JoinSlotCoverageChecker(List<Slot> left, List<Slot> right) {
+            leftExprIds = 
left.stream().map(Slot::getExprId).collect(Collectors.toSet());
+            rightExprIds = 
right.stream().map(Slot::getExprId).collect(Collectors.toSet());
         }
 
-        boolean isCoveredByLeftSlots(Set<SlotReference> slots) {
+        boolean isCoveredByLeftSlots(Set<Slot> slots) {
             return slots.stream()
-                    .map(SlotReference::getExprId)
+                    .map(Slot::getExprId)
                     .allMatch(leftExprIds::contains);
         }
 
-        boolean isCoveredByRightSlots(Set<SlotReference> slots) {
+        boolean isCoveredByRightSlots(Set<Slot> slots) {
             return slots.stream()
-                    .map(SlotReference::getExprId)
+                    .map(Slot::getExprId)
                     .allMatch(rightExprIds::contains);
         }
 
@@ -90,21 +89,21 @@ public class JoinUtils {
          * @return true if the equal can be used as hash join condition
          */
         boolean isHashJoinCondition(EqualTo equalTo) {
-            Set<SlotReference> equalLeft = 
equalTo.left().collect(SlotReference.class::isInstance);
+            Set<Slot> equalLeft = 
equalTo.left().collect(Slot.class::isInstance);
             if (equalLeft.isEmpty()) {
                 return false;
             }
 
-            Set<SlotReference> equalRight = 
equalTo.right().collect(SlotReference.class::isInstance);
+            Set<Slot> equalRight = 
equalTo.right().collect(Slot.class::isInstance);
             if (equalRight.isEmpty()) {
                 return false;
             }
 
             List<ExprId> equalLeftExprIds = equalLeft.stream()
-                    
.map(SlotReference::getExprId).collect(Collectors.toList());
+                    .map(Slot::getExprId).collect(Collectors.toList());
 
             List<ExprId> equalRightExprIds = equalRight.stream()
-                    
.map(SlotReference::getExprId).collect(Collectors.toList());
+                    .map(Slot::getExprId).collect(Collectors.toList());
             return leftExprIds.containsAll(equalLeftExprIds) && 
rightExprIds.containsAll(equalRightExprIds)
                     || leftExprIds.containsAll(equalRightExprIds) && 
rightExprIds.containsAll(equalLeftExprIds);
         }
@@ -119,8 +118,8 @@ public class JoinUtils {
         if (join.getOtherJoinCondition().isPresent()) {
             List<Expression> onExprs = ExpressionUtils.extractConjunction(
                     (Expression) join.getOtherJoinCondition().get());
-            List<SlotReference> leftSlots = 
Utils.getOutputSlotReference(join.left());
-            List<SlotReference> rightSlots = 
Utils.getOutputSlotReference(join.right());
+            List<Slot> leftSlots = join.left().getOutput();
+            List<Slot> rightSlots = join.right().getOutput();
             return extractExpressionForHashTable(leftSlots, rightSlots, 
onExprs);
         }
         return Pair.of(Lists.newArrayList(), Lists.newArrayList());
@@ -133,8 +132,8 @@ public class JoinUtils {
      * @param onConditions conditions to be split
      * @return pair of hashCondition and otherCondition
      */
-    public static Pair<List<Expression>, List<Expression>> 
extractExpressionForHashTable(List<SlotReference> leftSlots,
-            List<SlotReference> rightSlots, List<Expression> onConditions) {
+    public static Pair<List<Expression>, List<Expression>> 
extractExpressionForHashTable(List<Slot> leftSlots,
+            List<Slot> rightSlots, List<Expression> onConditions) {
         JoinSlotCoverageChecker checker = new 
JoinSlotCoverageChecker(leftSlots, rightSlots);
         Map<Boolean, List<Expression>> mapper = onConditions.stream()
                 .collect(Collectors.groupingBy(
@@ -154,19 +153,19 @@ public class JoinUtils {
         Pair<List<ExprId>, List<ExprId>> childSlotsExprId =
                 Pair.of(Lists.newArrayList(), Lists.newArrayList());
 
-        List<SlotReference> leftSlots = 
Utils.getOutputSlotReference(join.left());
-        List<SlotReference> rightSlots = 
Utils.getOutputSlotReference(join.right());
+        List<Slot> leftSlots = join.left().getOutput();
+        List<Slot> rightSlots = join.right().getOutput();
         List<EqualTo> equalToList = join.getHashJoinConjuncts().stream()
                 .map(e -> (EqualTo) e).collect(Collectors.toList());
         JoinSlotCoverageChecker checker = new 
JoinSlotCoverageChecker(leftSlots, rightSlots);
 
         for (EqualTo equalTo : equalToList) {
-            Set<SlotReference> leftOnSlots = 
equalTo.left().collect(SlotReference.class::isInstance);
-            Set<SlotReference> rightOnSlots = 
equalTo.right().collect(SlotReference.class::isInstance);
+            Set<Slot> leftOnSlots = 
equalTo.left().collect(Slot.class::isInstance);
+            Set<Slot> rightOnSlots = 
equalTo.right().collect(Slot.class::isInstance);
             List<ExprId> leftOnSlotsExprId = leftOnSlots.stream()
-                    
.map(SlotReference::getExprId).collect(Collectors.toList());
+                    .map(Slot::getExprId).collect(Collectors.toList());
             List<ExprId> rightOnSlotsExprId = rightOnSlots.stream()
-                    
.map(SlotReference::getExprId).collect(Collectors.toList());
+                    .map(Slot::getExprId).collect(Collectors.toList());
             if (checker.isCoveredByLeftSlots(leftOnSlots)
                     && checker.isCoveredByRightSlots(rightOnSlots)) {
                 childSlotsExprId.first.addAll(leftOnSlotsExprId);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java
index 217b224dc7..2adcbe9ab4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java
@@ -21,7 +21,6 @@ import org.apache.doris.nereids.exceptions.AnalysisException;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import org.apache.doris.nereids.trees.expressions.SlotReference;
 import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
-import org.apache.doris.nereids.trees.plans.Plan;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
@@ -116,15 +115,6 @@ public class Utils {
         return new HashSet<>(one).containsAll(other) && new 
HashSet<>(other).containsAll(one);
     }
 
-    /**
-     * Get SlotReference from output of plam.
-     * Warning, plan must have bound, because exists Slot Cast to 
SlotReference.
-     */
-    public static List<SlotReference> getOutputSlotReference(Plan plan) {
-        return plan.getOutput().stream().map(SlotReference.class::cast)
-                .collect(Collectors.toList());
-    }
-
     /**
      * Get sql string for plan.
      *


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

Reply via email to