twdsilva commented on code in PR #2876:
URL: https://github.com/apache/calcite/pull/2876#discussion_r1038666586
##########
core/src/test/java/org/apache/calcite/test/MaterializedViewRelOptRulesTest.java:
##########
@@ -338,6 +341,104 @@ protected final MaterializedViewFixture sql(String
materialize,
.ok();
}
+ @Test void testAggregateMaterializationAggregateFuncsRange1() {
+ // if range predicate aligns on the rollup column boundary verify that
only view is used
+ sql("select \"eventid\", floor(\"ts\" to minute), count(*) "
+ + "from \"events\""
+ + " group by \"eventid\", floor(\"ts\" to minute)",
+ "select \"eventid\", floor(\"ts\" to minute), count(*) \n"
+ + "from \"events\""
+ + " where \"ts\" >= TIMESTAMP'2018-01-01 00:02:00' "
+ + "AND \"ts\" < TIMESTAMP'2018-01-01 00:05:00'"
+ + "group by \"eventid\", floor(\"ts\" to minute)")
+ .checkingThatResultContains("EnumerableCalc(expr#0..2=[{inputs}], "
+ + "expr#3=[Sarg[[2018-01-01 00:02:00..2018-01-01 00:05:00)]],
expr#4=[SEARCH($t1, $t3)"
+ + "], proj#0..2=[{exprs}], $condition=[$t4])\n"
+ + " EnumerableTableScan(table=[[hr, MV0]])")
+ .withMetadataProvider(
+ ChainedRelMetadataProvider.of(
+ ImmutableList.of(TestMetadataHandlers.TestRelMdRowCount.SOURCE,
+ TestMetadataHandlers.TestRelMdSelectivity.SOURCE,
+ DefaultRelMetadataProvider.INSTANCE))
+ )
+ .ok();
+ }
+
+ @Test void testAggregateMaterializationAggregateFuncsRange2() {
+ // if range predicate doesn't align on the rollup column boundary verify
that a union on both
+ // the table and view is used
+ sql("select \"eventid\", floor(\"ts\" to minute), count(*) "
+ + "from \"events\""
+ + " group by \"eventid\", floor(\"ts\" to minute)",
+ "select \"eventid\", floor(\"ts\" to minute), count(*) \n"
+ + "from \"events\""
+ + " where \"ts\" > TIMESTAMP'2018-01-01 00:02:30.123' "
+ + "AND \"ts\" <= TIMESTAMP'2018-01-01 00:05:30.456'"
+ + "group by \"eventid\", floor(\"ts\" to minute)")
+ .checkingThatResultContains("EnumerableAggregate(group=[{0, 1}],
EXPR$2=[$SUM0($2)])\n"
+ + " EnumerableUnion(all=[true])\n"
+ + " EnumerableAggregate(group=[{0, 1}], EXPR$2=[COUNT()])\n"
+ + " EnumerableCalc(expr#0..1=[{inputs}],
expr#2=[FLAG(MINUTE)], expr#3=[FLOOR($t1,"
+ + " $t2)], expr#4=[Sarg[(2018-01-01
00:02:30.123:TIMESTAMP(3)..2018-01-01 "
+ + "00:03:00:TIMESTAMP(3)), [2018-01-01
00:05:00:TIMESTAMP(3)..2018-01-01 00:05:30"
+ + ".456:TIMESTAMP(3)]]:TIMESTAMP(3)], expr#5=[SEARCH($t1, $t4)],
eventid=[$t0], "
+ + "$f1=[$t3], $condition=[$t5])\n"
+ + " EnumerableTableScan(table=[[hr, events]])\n"
+ + " EnumerableCalc(expr#0..2=[{inputs}],
expr#3=[Sarg[[2018-01-01 00:03:00."
+ + ".2018-01-01 00:05:00)]], expr#4=[SEARCH($t1, $t3)],
proj#0..2=[{exprs}], "
+ + "$condition=[$t4])\n"
+ + " EnumerableTableScan(table=[[hr, MV0]])")
+ .withMetadataProvider(
+ ChainedRelMetadataProvider.of(
+ ImmutableList.of(TestMetadataHandlers.TestRelMdRowCount.SOURCE,
+ TestMetadataHandlers.TestRelMdSelectivity.SOURCE,
+ DefaultRelMetadataProvider.INSTANCE))
+ )
+ .ok();
+ }
+
+ @Test void testAggregateMaterializationAggregateFuncsRange31() {
+ // test using multiple views
Review Comment:
Added a more descriptive comment.
--
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]