xy2953396112 commented on a change in pull request #2365:
URL: https://github.com/apache/calcite/pull/2365#discussion_r590152726



##########
File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
##########
@@ -1550,6 +1552,43 @@ private AggregateOnCalcToAggregateUnifyRule() {
     }
   }
 
+  /** A {@link SubstitutionVisitor.UnifyRule} that matches a
+   * {@link org.apache.calcite.rel.core.Join} to a
+   * {@link org.apache.calcite.rel.core.Join}, provided
+   * that they have the same child. */
+  private static class JoinToJoinUnifyRule extends AbstractUnifyRule {
+    public static final JoinToJoinUnifyRule INSTANCE = new 
JoinToJoinUnifyRule();
+    private JoinToJoinUnifyRule() {
+      super(operand(MutableJoin.class, query(0)),
+          operand(MutableJoin.class, target(0)), 1);
+    }
+
+    @Override protected UnifyResult apply(UnifyRuleCall call) {
+      MutableJoin query = (MutableJoin) call.query;
+      MutableJoin target = (MutableJoin) call.target;
+
+      // same join type
+      final JoinRelType joinRelType = sameJoinType(query.joinType, 
target.joinType);
+      if (joinRelType == null) {
+        return null;
+      }
+      List<RexNode> queryCondition = RelOptUtil.conjunctions(query.condition);
+      List<RexNode> targetCondition = 
RelOptUtil.conjunctions(target.condition);
+      // same join condition
+      if (queryCondition.size() == targetCondition.size()) {
+        Set<String> queryConditionDigest = queryCondition.stream()
+            .map(rex -> rex.toString()).collect(Collectors.toSet());
+        Set<String> targetConditionDigest = targetCondition.stream()
+            .map(rex -> rex.toString()).collect(Collectors.toSet());

Review comment:
       ok




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to