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/10/23 13:03:44 UTC

[GitHub] [calcite] jinxing64 commented on a change in pull request #1526: [CALCITE-3439] Support Intersect and Minus in RelMdPredicates

jinxing64 commented on a change in pull request #1526: [CALCITE-3439] Support Intersect and Minus in RelMdPredicates
URL: https://github.com/apache/calcite/pull/1526#discussion_r338033402
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
 ##########
 @@ -410,6 +414,50 @@ public RelOptPredicateList getPredicates(Union union, RelMetadataQuery mq) {
     return RelOptPredicateList.of(rexBuilder, predicates);
   }
 
+  /**
+   * Infers predicates for a Intersect.
+   */
+  public RelOptPredicateList getPredicates(Intersect intersect, RelMetadataQuery mq) {
+    final RexBuilder rexBuilder = intersect.getCluster().getRexBuilder();
+
+    final RexExecutorImpl rexImpl =
+        (RexExecutorImpl) (intersect.getCluster().getPlanner().getExecutor());
+    final RexImplicationChecker rexImplicationChecker =
+        new RexImplicationChecker(
+            intersect.getCluster().getRexBuilder(), rexImpl, intersect.getRowType());
+
+    Set<RexNode> finalPredicates = new HashSet<>();
+    RexNode composedFinalPredicates = null;
+    for (Ord<RelNode> input : Ord.zip(intersect.getInputs())) {
+      RelOptPredicateList info = mq.getPulledUpPredicates(input.e);
+      if (info.pulledUpPredicates.isEmpty()) {
+        return RelOptPredicateList.EMPTY;
+      }
+      final Set<RexNode> predicates = new HashSet<>();
+      for (RexNode pred : info.pulledUpPredicates) {
+        if (input.i == 0) {
+          predicates.add(pred);
+          continue;
+        } else if (rexImplicationChecker.implies(composedFinalPredicates, pred)) {
+          predicates.add(pred);
+        }
+      }
+      finalPredicates = predicates;
+      composedFinalPredicates = RexUtil.composeConjunction(
+          rexBuilder, finalPredicates);
+    }
+
+    return RelOptPredicateList.of(rexBuilder, finalPredicates);
+  }
+
+  /**
+   * Infers predicates for a Intersect.
 
 Review comment:
   sure

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