morrySnow commented on code in PR #14051:
URL: https://github.com/apache/doris/pull/14051#discussion_r1016844580


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java:
##########
@@ -318,4 +319,11 @@ public static void addSlotsUsedByOn(Set<Slot> usedSlots, 
List<NamedExpression> p
             }
         });
     }
+
+    public static Set<Slot> getJoinOutput(Plan left, Plan right) {
+        HashSet<Slot> joinOutput = new HashSet<>();
+        joinOutput.addAll(left.getOutput());
+        joinOutput.addAll(right.getOutput());

Review Comment:
   ```suggestion
           joinOutput.addAll(left.getOutputSet());
           joinOutput.addAll(right.getOutputSet());
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java:
##########
@@ -318,4 +319,11 @@ public static void addSlotsUsedByOn(Set<Slot> usedSlots, 
List<NamedExpression> p
             }
         });
     }
+
+    public static Set<Slot> getJoinOutput(Plan left, Plan right) {

Review Comment:
   ```suggestion
       public static Set<Slot> getJoinOutputSet(Plan left, Plan right) {
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinExchange.java:
##########
@@ -0,0 +1,136 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.exploration.join;
+
+import org.apache.doris.nereids.annotation.Developing;
+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.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+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 org.apache.doris.nereids.util.JoinUtils;
+
+import com.google.common.collect.Lists;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * rule factory for exchange without inside-project.
+ */
+@Developing
+public class JoinExchange extends OneExplorationRuleFactory {
+    public static final JoinExchange INSTANCE = new JoinExchange();
+
+    /*
+     *        topJoin                      newTopJoin
+     *        /      \                      /      \
+     *   leftJoin  rightJoin   -->   newLeftJoin newRightJoin
+     *    /    \    /    \            /    \        /    \
+     *   A      B  C      D          A      C      B      D
+     */
+    @Override
+    public Rule build() {
+        return innerLogicalJoin(innerLogicalJoin(), innerLogicalJoin())
+                .when(JoinExchange::checkReorder)
+                .then(topJoin -> {
+                    LogicalJoin<GroupPlan, GroupPlan> leftJoin = 
topJoin.left();
+                    LogicalJoin<GroupPlan, GroupPlan> rightJoin = 
topJoin.right();
+                    GroupPlan a = leftJoin.left();
+                    GroupPlan b = leftJoin.right();
+                    GroupPlan c = rightJoin.left();
+                    GroupPlan d = rightJoin.right();
+
+                    Set<Slot> acOutputSet = JoinUtils.getJoinOutput(a, c);
+                    Set<Slot> bdOutputSet = JoinUtils.getJoinOutput(b, d);
+
+                    List<Expression> newLeftJoinHashJoinConjuncts = 
Lists.newArrayList();
+                    List<Expression> newRightJoinHashJoinConjuncts = 
Lists.newArrayList();
+                    List<Expression> newTopJoinHashJoinConjuncts = new 
ArrayList<>(leftJoin.getHashJoinConjuncts());
+                    
newTopJoinHashJoinConjuncts.addAll(rightJoin.getHashJoinConjuncts());
+                    splitTopConditon(topJoin.getHashJoinConjuncts(), 
acOutputSet, bdOutputSet,
+                            newLeftJoinHashJoinConjuncts, 
newRightJoinHashJoinConjuncts, newTopJoinHashJoinConjuncts);

Review Comment:
   should we avoid generate cross join?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to