You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2021/03/15 03:02:46 UTC

[GitHub] [calcite] chunweilei commented on a change in pull request #2365: [CALCITE-4391] Implement JoinToJoinUnifyRule in SubstitutionVisitor

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



##########
File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
##########
@@ -1550,6 +1552,41 @@ 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 @Nullable 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<RexNode> queryConditionDigest = queryCondition.stream().collect(Collectors.toSet());
+        Set<RexNode> targetConditionDigest = targetCondition.stream().collect(Collectors.toSet());

Review comment:
       +1 for @vlsi 

##########
File path: core/src/test/java/org/apache/calcite/materialize/NormalizationTrimFieldTest.java
##########
@@ -106,4 +116,41 @@
     final String relOptimizedStr = RelOptUtil.toString(relOptimized.get(0).getKey());
     assertThat(isLinux(optimized).matches(relOptimizedStr), is(true));
   }
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4391">[CALCITE-4391]
+   * The order of join conditions is different,materialized view recognition fails</a>. */
+  @Test void testJoinToJoinConditionReorder() {
+    final RelBuilder relBuilder = RelBuilder.create(config().build());

Review comment:
       The order of join conditions is different, materialized view recognition fails -> materialized view recognition fails when the order of join conditions is different?




----------------------------------------------------------------
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:
users@infra.apache.org