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/08/25 21:29:35 UTC

[GitHub] [calcite] sdreynolds commented on a diff in pull request #2876: [CALCITE-5240] Enhance MaterializedViewRule so that it applies to rol…

sdreynolds commented on code in PR #2876:
URL: https://github.com/apache/calcite/pull/2876#discussion_r955438436


##########
core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewRule.java:
##########
@@ -485,6 +516,54 @@ protected void perform(RelOptRuleCall call, @Nullable Project topProject, RelNod
     }
   }
 
+  private static RelNode getViewWithFilter(RelNode view, @Nullable RexNode viewFilter,
+      RelBuilder builder, @Nullable RexNode newPred) {
+    RelNode viewWithFilter;
+    if (viewFilter != null) {
+      viewWithFilter = builder.push(view).filter(viewFilter).build();
+    } else if (newPred != null) {
+      viewWithFilter = builder.push(view).filter(newPred).build();
+    } else {
+      viewWithFilter = builder.push(view).build();
+    }
+    return viewWithFilter;
+  }
+
+  /**
+   * If the view contains a FLOOR(col) and the query contains a range predicate on the col then
+   * generate a filter on the view based on the query predicate so that the view can be used.
+   */
+  private @Nullable Pair<RexNode, RexNode> generateViewPredicateAndFilter(RelNode view,
+      RelNode viewNode, RexBuilder rexBuilder, Pair<RexNode, RexNode> queryPreds) {
+    if (viewNode instanceof Aggregate) {
+      Aggregate aggregate = (Aggregate) viewNode;
+      RelNode input = aggregate.getInput();
+      if (input instanceof Project) {
+        Project project = (Project) input;
+        int viewColumnIndex = 0;
+        for (RexNode rexNode : project.getProjects()) {
+          if (rexNode instanceof RexCall) {
+            RexCall rexCall = (RexCall) rexNode;
+            if (rexCall.getOperator() instanceof SqlFloorFunction) {

Review Comment:
   Should this compare based on `SqlKind` ? https://github.com/apache/calcite/blob/b9c2099ea92a575084b55a206efc5dd341c0df62/core/src/main/java/org/apache/calcite/sql/SqlKind.java



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