asolimando commented on code in PR #2876:
URL: https://github.com/apache/calcite/pull/2876#discussion_r1020889953
##########
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()) {
+ // If there is no view predicate add one based on the query predicate if
the
+ // view is a rollup ( contains an aggregation that groups by FLOOR )
+ 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;
Review Comment:
I feel this is the right spot where an auxiliary method could be extracted,
`rewriteInputView` is too long and does a lot of things, what do you think?
--
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]