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


##########
core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewAggregateRule.java:
##########
@@ -292,10 +298,36 @@
                 otherCompensationPred)));
 
     // Generate query rewriting.
-    RelNode rewrittenPlan = relBuilder
-        .push(target)
-        .filter(simplify.simplifyUnknownAsFalse(queryCompensationPred))
-        .build();
+    RelNode rewrittenPlan = null;
+    if (pushQueryFilter) {
+      rewrittenPlan = target.accept(
+          // Push the queryCompensationPred down into any filter that is 
present in the plan
+          new RelShuttleImpl() {
+            @Override public RelNode visit(LogicalFilter filter) {
+              RexNode condition =
+                  RexUtil.flatten(rexBuilder,
+                      rexBuilder.makeCall(
+                          SqlStdOperatorTable.AND,
+                          filter.getCondition(),
+                          queryCompensationPred));
+              return filter.copy(filter.getTraitSet(), filter.getInput(), 
condition);
+            }
+
+            @Override public RelNode visit(RelNode other) {
+              if (other instanceof RelSubset) {
+                RelSubset relSubset = (RelSubset) other;
+                return relSubset.getBestOrOriginal().accept(this);
+              } else {
+                return visitChildren(other);
+              }
+            }
+          });
+    } else {
+      rewrittenPlan = relBuilder
+          .push(target)

Review Comment:
   I think it's worth extracting the `RelShuttleImpl` to a private class to 
improve readability



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