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 2019/11/16 06:02:55 UTC

[GitHub] [calcite] danny0405 commented on a change in pull request #1589: [CALCITE-3508] Strengthen Outer Joins based on FILTER clauses

danny0405 commented on a change in pull request #1589: [CALCITE-3508] Strengthen Outer Joins based on FILTER clauses
URL: https://github.com/apache/calcite/pull/1589#discussion_r347078340
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java
 ##########
 @@ -156,6 +161,52 @@ protected void perform(RelOptRuleCall call, Filter filter,
     final List<RexNode> leftFilters = new ArrayList<>();
     final List<RexNode> rightFilters = new ArrayList<>();
 
+    final int nFieldsLeft = join
+        .getInputs()
+        .get(0)
+        .getRowType()
+        .getFieldList()
+        .size();
+    final int nFieldsRight = join
+        .getInputs()
+        .get(1)
+        .getRowType()
+        .getFieldList()
+        .size();
+
+    final int nTotalFields = join.getRowType().getFieldList().size();
+    final int nSysFields = 0; // joinRel.getSystemFieldList().size();
+
+    // Setup two bit sets, one for the left side of the join indicating what fields are present
+    // in the left side of the join and the other for the right side.
+    final ImmutableBitSet leftBitmap = ImmutableBitSet.range(
+        nSysFields, nSysFields + nFieldsLeft);
+    final ImmutableBitSet rightBitmap = ImmutableBitSet.range(
+        nSysFields + nFieldsLeft, nTotalFields);
+
+    // When a join can create nulls on the left (or right) leverage the filter to determine if
+    // the join can cancel nulls on left (or right).
+    if (joinType.generatesNullsOnLeft() && filter != null) {
+      final RexVisitor<Boolean> mustMatchSideVisitor = new TableNotNullable(leftBitmap);
+      final Boolean filterMustMatch = filter.getCondition().accept(mustMatchSideVisitor);
+      if (filterMustMatch != null) {
+        if (filterMustMatch != Boolean.FALSE) {
+          joinType = joinType.cancelNullsOnLeft();
+        }
+      }
+    }
+
+    // When a join can create nulls on the right (or left) leverage the filter to determine if
+    // the join can cancel nulls on right (or left).
+    if (joinType.generatesNullsOnRight() && filter != null) {
+      final RexVisitor<Boolean> mustMatchSideVisitor = new TableNotNullable(rightBitmap);
+      final Boolean filterMustMatch = filter.getCondition().accept(mustMatchSideVisitor);
+      if (filterMustMatch != null) {
+        if (filterMustMatch != Boolean.FALSE) {
 
 Review comment:
   When the `filterMustMatch ` can be null ?

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


With regards,
Apache Git Services