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


##########
core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewAggregateRule.java:
##########
@@ -910,6 +942,53 @@ protected SqlFunction getFloorSqlFunction(TimeUnitRange 
flag) {
     return Pair.of(resultTopViewProject, requireNonNull(resultViewNode, 
"resultViewNode"));
   }
 
+  /**
+   * If the view contains a FLOOR(col) and the query contains a range 
predicate on the col then
+   * rewrite the view to include a predicate based on the query predicate so 
that the view
+   * can be used.
+   * @return pair of view and added view predicate, or null if the rewrite 
can't be done
+   */
+  @Override public @Nullable  Pair<RelNode, RexNode> 
rewriteInputView(RelOptRuleCall call,
+      RelNode view, RelNode viewNode, RexBuilder rexBuilder, Pair<RexNode, 
RexNode> queryPreds,
+      RexNode viewPred) {
+    if (!queryPreds.right.isAlwaysTrue() && viewPred.isAlwaysTrue()) {

Review Comment:
   `queryPreds.right` is nullable here, we need to check for `queryPreds.right 
!= null` before invoking a method to avoid NPE



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to