mirror of https://github.com/apache/druid.git
parent
bf1d1d583b
commit
cd6af93274
|
@ -7272,6 +7272,55 @@ public class GroupByQueryRunnerTest extends InitializedNullHandlingTest
|
|||
TestHelper.assertExpectedObjects(expectedResults, results, "subtotal-order-limit");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testGroupByWithSubtotalsSpecWithOrderLimitForcePushdown()
|
||||
{
|
||||
if (!config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GroupByQuery query = makeQueryBuilder()
|
||||
.setDataSource(QueryRunnerTestHelper.DATA_SOURCE)
|
||||
.setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD)
|
||||
.setDimensions(Lists.newArrayList(
|
||||
new DefaultDimensionSpec("placement", "placement"),
|
||||
new DefaultDimensionSpec("market", "market")
|
||||
))
|
||||
.setAggregatorSpecs(
|
||||
Arrays.asList(
|
||||
QueryRunnerTestHelper.ROWS_COUNT,
|
||||
new LongSumAggregatorFactory("idx", "index")
|
||||
)
|
||||
)
|
||||
.setGranularity(QueryRunnerTestHelper.DAY_GRAN)
|
||||
.setSubtotalsSpec(ImmutableList.of(
|
||||
ImmutableList.of("placement"),
|
||||
ImmutableList.of("market"),
|
||||
ImmutableList.of()
|
||||
))
|
||||
.setLimitSpec(DefaultLimitSpec.builder().limit(25).orderBy("placement", "market").build())
|
||||
.overrideContext(ImmutableMap.of(GroupByQueryConfig.CTX_KEY_FORCE_LIMIT_PUSH_DOWN, true))
|
||||
.build();
|
||||
|
||||
List<ResultRow> expectedResults = Arrays.asList(
|
||||
makeRow(query, "2011-04-01", "placement", "preferred", "market", null, "rows", 13L, "idx", 6619L),
|
||||
makeRow(query, "2011-04-02", "placement", "preferred", "market", null, "rows", 13L, "idx", 5827L),
|
||||
makeRow(query, "2011-04-01", "placement", null, "market", "spot", "rows", 9L, "idx", 1102L),
|
||||
makeRow(query, "2011-04-01", "placement", null, "market", "total_market", "rows", 2L, "idx", 2836L),
|
||||
makeRow(query, "2011-04-01", "placement", null, "market", "upfront", "rows", 2L, "idx", 2681L),
|
||||
makeRow(query, "2011-04-02", "placement", null, "market", "spot", "rows", 9L, "idx", 1120L),
|
||||
makeRow(query, "2011-04-02", "placement", null, "market", "total_market", "rows", 2L, "idx", 2514L),
|
||||
makeRow(query, "2011-04-02", "placement", null, "market", "upfront", "rows", 2L, "idx", 2193L),
|
||||
makeRow(query, "2011-04-01", "placement", null, "market", null, "rows", 13L, "idx", 6619L),
|
||||
makeRow(query, "2011-04-02", "placement", null, "market", null, "rows", 13L, "idx", 5827L)
|
||||
);
|
||||
|
||||
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
|
||||
TestHelper.assertExpectedObjects(expectedResults, results, "subtotal-order-limit");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroupByWithTimeColumn()
|
||||
{
|
||||
|
|
|
@ -16349,11 +16349,13 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
|
|||
ImmutableList.of("d1"),
|
||||
ImmutableList.of()
|
||||
)
|
||||
).setLimitSpec(
|
||||
new DefaultLimitSpec(
|
||||
ImmutableList.of(),
|
||||
100)
|
||||
)
|
||||
)
|
||||
.setLimitSpec(
|
||||
new DefaultLimitSpec(
|
||||
ImmutableList.of(),
|
||||
100
|
||||
)
|
||||
)
|
||||
.setContext(QUERY_CONTEXT_DEFAULT)
|
||||
.build()
|
||||
),
|
||||
|
@ -16373,6 +16375,81 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroupingSetsWithLimitOrderByGran() 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), () ) ORDER BY x.gran LIMIT 100",
|
||||
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", "d0"),
|
||||
new DefaultDimensionSpec("v1", "d1", ValueType.LONG)
|
||||
)
|
||||
)
|
||||
.setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt")))
|
||||
.setSubtotalsSpec(
|
||||
ImmutableList.of(
|
||||
ImmutableList.of("d0", "d1"),
|
||||
ImmutableList.of("d0"),
|
||||
ImmutableList.of("d1"),
|
||||
ImmutableList.of()
|
||||
)
|
||||
)
|
||||
.setLimitSpec(
|
||||
new DefaultLimitSpec(
|
||||
ImmutableList.of(
|
||||
new OrderByColumnSpec(
|
||||
"d1",
|
||||
Direction.ASCENDING,
|
||||
new StringComparators.NumericComparator()
|
||||
)
|
||||
),
|
||||
100
|
||||
)
|
||||
)
|
||||
.setContext(QUERY_CONTEXT_DEFAULT)
|
||||
.build()
|
||||
),
|
||||
ImmutableList.<Object[]>builder().add(
|
||||
new Object[]{"", null, 2L},
|
||||
new Object[]{"a", null, 1L},
|
||||
new Object[]{"", null, 1L},
|
||||
new Object[]{"a", null, 1L},
|
||||
new Object[]{"abc", null, 1L},
|
||||
new Object[]{NULL_STRING, null, 6L},
|
||||
new Object[]{"", timestamp("2000-01-01"), 2L},
|
||||
new Object[]{"a", timestamp("2000-01-01"), 1L},
|
||||
new Object[]{NULL_STRING, timestamp("2000-01-01"), 3L},
|
||||
new Object[]{"", timestamp("2001-01-01"), 1L},
|
||||
new Object[]{"a", timestamp("2001-01-01"), 1L},
|
||||
new Object[]{"abc", timestamp("2001-01-01"), 1L},
|
||||
new Object[]{NULL_STRING, timestamp("2001-01-01"), 3L}
|
||||
).build()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a provider of query contexts that should be used by join tests.
|
||||
* It tests various configs that can be passed to join queries. All the configs provided by this provider should
|
||||
|
|
Loading…
Reference in New Issue