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 2022/05/19 12:07:56 UTC

[GitHub] [calcite] libenchao commented on a diff in pull request #2761: [CALCITE-5073] JoinConditionPushRule cannot infer 'LHS.C1 = LHS.C2' f…

libenchao commented on code in PR #2761:
URL: https://github.com/apache/calcite/pull/2761#discussion_r876973627


##########
core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java:
##########
@@ -225,6 +232,105 @@ protected void perform(RelOptRuleCall call, @Nullable Filter filter,
     call.transformTo(relBuilder.build());
   }
 
+  /**
+   * Infer more equal conditions for the Join Condition.
+   *
+   * <p> For example, in {@code SELECT * FROM T1, T2, T3 WHERE T1.id = T3.id AND T2.id = T3.id},
+   * we can infer {@code T1.id = T2.id} for the first Join node from second Join node's condition:
+   * {@code T1.id = T3.id AND T2.id = T3.id}.
+   *
+   * <p>For the above SQL, the second Join's condition is {@code T1.id = T3.id AND T2.id = T3.id}.
+   * After inference, the final condition would be: {@code T1.id = T2.id AND T1.id = T3.id}, the
+   * {@code T1.id = T2.id} can be further pushed into LHS.
+   *
+   * @param rexNodes the Join condition
+   * @param join the Join node
+   */
+  protected void inferJoinEqualConditions(List<RexNode> rexNodes, Join join) {
+    final List<Set<Integer>> equalSets = new ArrayList<>();
+    final List<RexNode> result = new ArrayList<>(rexNodes.size());
+    for (RexNode rexNode : rexNodes) {
+      if (rexNode.isA(SqlKind.EQUALS)) {
+        final RexNode op1 = ((RexCall) rexNode).getOperands().get(0);
+        final RexNode op2 = ((RexCall) rexNode).getOperands().get(1);

Review Comment:
   I agree with you. However, I just followed  `FilterJoinRule#validateJoinFilters`, and kept it same. (Of course, if you still think we'd better to make it a no side-effect method, I can refactor it)



-- 
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-unsubscribe@calcite.apache.org

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