gianm commented on code in PR #13206:
URL: https://github.com/apache/druid/pull/13206#discussion_r997204198
##########
sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java:
##########
@@ -6948,6 +6947,87 @@ public void
testExactCountDistinctUsingSubqueryOnUnionAllTables()
);
}
+ @Test
+ public void testUseTimeFloorInsteadOfGranularityOnJoinResult()
+ {
+ cannotVectorize();
+
+ testQuery(
+ "WITH main AS (SELECT * FROM foo LIMIT 2)\n"
+ + "SELECT TIME_FLOOR(__time, 'PT1H') AS \"time\", dim1, COUNT(*)\n"
+ + "FROM main\n"
+ + "WHERE dim1 IN (SELECT dim1 FROM main GROUP BY 1 ORDER BY COUNT(*)
DESC LIMIT 5)\n"
+ + "GROUP BY 1, 2",
+ ImmutableList.of(
+ GroupByQuery.builder()
+ .setDataSource(
+ join(
+ new QueryDataSource(
+ newScanQueryBuilder()
+ .dataSource(CalciteTests.DATASOURCE1)
+
.intervals(querySegmentSpec(Intervals.ETERNITY))
+ .columns("__time", "dim1")
+ .limit(2)
+ .build()
+ ),
+ new QueryDataSource(
+ GroupByQuery.builder()
+ .setDataSource(
+ new QueryDataSource(
+ newScanQueryBuilder()
+
.dataSource(CalciteTests.DATASOURCE1)
+
.intervals(querySegmentSpec(Intervals.ETERNITY))
+ .columns("dim1")
+ .limit(2)
+ .build()
+ )
+ )
+
.setInterval(querySegmentSpec(Intervals.ETERNITY))
+
.setGranularity(Granularities.ALL)
+ .setDimensions(dimensions(new
DefaultDimensionSpec("dim1", "d0")))
+
.setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0")))
+ .setLimitSpec(
+ new DefaultLimitSpec(
+ ImmutableList.of(
+ new
OrderByColumnSpec(
+ "a0",
+
Direction.DESCENDING,
+
StringComparators.NUMERIC
+ )
+ ),
+ 5
+ )
+ )
+ .build()
+ ),
+ "j0.",
+ "(\"dim1\" == \"j0.d0\")",
+ JoinType.INNER
+ )
+ )
+ .setInterval(querySegmentSpec(Filtration.eternity()))
+ .setGranularity(Granularities.ALL)
+ .setVirtualColumns(
+ expressionVirtualColumn(
+ "v0",
+
"timestamp_floor(\"__time\",'PT1H',null,'UTC')",
+ ColumnType.LONG
+ )
+ )
+ .setDimensions(dimensions(
+ new DefaultDimensionSpec("v0", "d0",
ColumnType.LONG),
+ new DefaultDimensionSpec("dim1", "d1")
+ ))
+ .setAggregatorSpecs(aggregators(new
CountAggregatorFactory("a0")))
+ .setContext(QUERY_CONTEXT_DEFAULT)
+ .build()
+ ),
+ NullHandling.sqlCompatible()
+ ? ImmutableList.of(new Object[]{946684800000L, "", 1L}, new
Object[]{946771200000L, "10.1", 1L})
Review Comment:
Yes, that's exactly what is happening.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]