gianm commented on a change in pull request #9122: Add SQL GROUPING SETS
support.
URL: https://github.com/apache/druid/pull/9122#discussion_r384092390
##########
File path: sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
##########
@@ -9579,6 +9600,538 @@ public void testGroupByTimeAndOtherDimension() throws
Exception
);
}
+ @Test
+ public void testGroupingSets() throws Exception
+ {
+ // Cannot vectorize due to virtual columns.
+ cannotVectorize();
+
+ testQuery(
+ "SELECT dim2, gran, SUM(cnt)\n"
+ + "FROM (SELECT FLOOR(__time TO MONTH) AS gran, COALESCE(dim2, '')
dim2, cnt FROM druid.foo) AS x\n"
+ + "GROUP BY GROUPING SETS ( (dim2, gran), (dim2), (gran), () )",
+ ImmutableList.of(
+ GroupByQuery.builder()
+ .setDataSource(CalciteTests.DATASOURCE1)
+ .setInterval(querySegmentSpec(Filtration.eternity()))
+ .setGranularity(Granularities.ALL)
+ .setVirtualColumns(
+ expressionVirtualColumn(
+ "v0",
+ "case_searched(notnull(\"dim2\"),\"dim2\",'')",
+ ValueType.STRING
+ ),
+ expressionVirtualColumn(
+ "v1",
+ "timestamp_floor(\"__time\",'P1M',null,'UTC')",
+ ValueType.LONG
+ )
+ )
+ .setDimensions(
+ dimensions(
+ new DefaultDimensionSpec("v0", "v0"),
+ new DefaultDimensionSpec("v1", "v1",
ValueType.LONG)
+ )
+ )
+ .setAggregatorSpecs(aggregators(new
LongSumAggregatorFactory("a0", "cnt")))
+ .setSubtotalsSpec(
+ ImmutableList.of(
+ ImmutableList.of("v0", "v1"),
+ ImmutableList.of("v0"),
+ ImmutableList.of("v1"),
+ ImmutableList.of()
+ )
+ )
+ .setContext(QUERY_CONTEXT_DEFAULT)
+ .build()
+ ),
+ ImmutableList.of(
+ new Object[]{"", timestamp("2000-01-01"), 2L},
+ new Object[]{"", timestamp("2001-01-01"), 1L},
+ new Object[]{"a", timestamp("2000-01-01"), 1L},
+ new Object[]{"a", timestamp("2001-01-01"), 1L},
+ new Object[]{"abc", timestamp("2001-01-01"), 1L},
+ new Object[]{"", null, 3L},
+ new Object[]{"a", null, 2L},
+ new Object[]{"abc", null, 1L},
+ new Object[]{NULL_VALUE, timestamp("2000-01-01"), 3L},
+ new Object[]{NULL_VALUE, timestamp("2001-01-01"), 3L},
+ new Object[]{NULL_VALUE, null, 6L}
+ )
+ );
+ }
+
+ @Test
+ public void testGroupingSetsWithNumericDimension() throws Exception
+ {
+ testQuery(
+ "SELECT cnt, COUNT(*)\n"
+ + "FROM foo\n"
+ + "GROUP BY GROUPING SETS ( (cnt), () )",
+ ImmutableList.of(
+ GroupByQuery.builder()
+ .setDataSource(CalciteTests.DATASOURCE1)
+ .setInterval(querySegmentSpec(Filtration.eternity()))
+ .setGranularity(Granularities.ALL)
+ .setDimensions(dimensions(new
DefaultDimensionSpec("cnt", "d0", ValueType.LONG)))
+ .setAggregatorSpecs(aggregators(new
CountAggregatorFactory("a0")))
+ .setSubtotalsSpec(
+ ImmutableList.of(
+ ImmutableList.of("d0"),
+ ImmutableList.of()
+ )
+ )
+ .setContext(QUERY_CONTEXT_DEFAULT)
+ .build()
+ ),
+ ImmutableList.of(
+ new Object[]{1L, 6L},
+ new Object[]{null, 6L}
+ )
+ );
+ }
+
+ @Test
+ public void testGroupByRollup() throws Exception
+ {
+ // Cannot vectorize due to virtual columns.
+ cannotVectorize();
+
+ testQuery(
+ "SELECT dim2, gran, SUM(cnt)\n"
+ + "FROM (SELECT FLOOR(__time TO MONTH) AS gran, COALESCE(dim2, '')
dim2, cnt FROM druid.foo) AS x\n"
+ + "GROUP BY ROLLUP (dim2, gran)",
Review comment:
OK, I'll add it.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]