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 2020/11/16 10:24:08 UTC

[GitHub] [calcite] chunweilei commented on a change in pull request #1983: [CALCITE-4005] Support calc operator in RelMdAllPredicates

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



##########
File path: core/src/main/java/org/apache/calcite/rel/metadata/RelMdAllPredicates.java
##########
@@ -120,12 +124,35 @@ public RelOptPredicateList getAllPredicates(Project project, RelMetadataQuery mq
   }
 
   /**
-   * Add the Filter condition to the list obtained from the input.
+   * Extract predicates for a Filter.
    */
   public RelOptPredicateList getAllPredicates(Filter filter, RelMetadataQuery mq) {
-    final RelNode input = filter.getInput();
-    final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
-    final RexNode pred = filter.getCondition();
+    return getAllFilterPredicates(filter, mq, filter.getCondition());
+  }
+
+  /**
+   * Extract predicates for a Calc.
+   */
+  public RelOptPredicateList getAllPredicates(Calc calc, RelMetadataQuery mq) {
+    final RexProgram rexProgram = calc.getProgram();
+    List<RexNode> condition = new ArrayList<>();
+    if (rexProgram.getCondition() != null) {
+      condition = Util.transform(ImmutableList.of(rexProgram.getCondition()),
+          rexProgram::expandLocalRef);
+    } else {
+      return mq.getAllPredicates(calc.getInput());

Review comment:
       The type of `condition` can be RexNode rather than List<RexNode>.

##########
File path: core/src/main/java/org/apache/calcite/rel/metadata/RelMdAllPredicates.java
##########
@@ -120,12 +124,35 @@ public RelOptPredicateList getAllPredicates(Project project, RelMetadataQuery mq
   }
 
   /**
-   * Add the Filter condition to the list obtained from the input.
+   * Extract predicates for a Filter.
    */
   public RelOptPredicateList getAllPredicates(Filter filter, RelMetadataQuery mq) {
-    final RelNode input = filter.getInput();
-    final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
-    final RexNode pred = filter.getCondition();
+    return getAllFilterPredicates(filter, mq, filter.getCondition());
+  }
+
+  /**
+   * Extract predicates for a Calc.
+   */
+  public RelOptPredicateList getAllPredicates(Calc calc, RelMetadataQuery mq) {
+    final RexProgram rexProgram = calc.getProgram();
+    List<RexNode> condition = new ArrayList<>();

Review comment:
       Extract -> Extracts




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