use of org.apache.druid.query.dimension.DefaultDimensionSpec in project druid by druid-io.
the class CalciteQueryTest method testGroupingSetsWithOrderByAggregatorWithLimit.
@Test
public void testGroupingSetsWithOrderByAggregatorWithLimit() 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) )\n" + "ORDER BY SUM(cnt)\n" + "LIMIT 1", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "case_searched(notnull(\"dim2\"),\"dim2\",'')", ColumnType.STRING), expressionVirtualColumn("v1", "timestamp_floor(\"__time\",'P1M',null,'UTC')", ColumnType.LONG)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "d0"), new DefaultDimensionSpec("v1", "d1", ColumnType.LONG))).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt"))).setSubtotalsSpec(ImmutableList.of(ImmutableList.of("d0"), ImmutableList.of("d1"), ImmutableList.of())).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("a0", Direction.ASCENDING, StringComparators.NUMERIC)), 1)).setContext(withTimestampResultContext(QUERY_CONTEXT_DEFAULT, "d1", 1, Granularities.MONTH)).build()), ImmutableList.of(new Object[] { "abc", null, 1L }));
}
use of org.apache.druid.query.dimension.DefaultDimensionSpec in project druid by druid-io.
the class CalciteQueryTest method testGroupByWithForceLimitPushDown.
@Test
public void testGroupByWithForceLimitPushDown() throws Exception {
final Map<String, Object> context = new HashMap<>(QUERY_CONTEXT_DEFAULT);
context.put(GroupByQueryConfig.CTX_KEY_FORCE_LIMIT_PUSH_DOWN, true);
testQuery("SELECT dim1, dim2, COUNT(*) FROM druid.foo GROUP BY dim1, dim2 limit 1", context, ImmutableList.of(new GroupByQuery.Builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("dim1", "d0", ColumnType.STRING), new DefaultDimensionSpec("dim2", "d1", ColumnType.STRING)).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(), 1)).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(context).build()), ImmutableList.of(new Object[] { "", "a", 1L }));
}
use of org.apache.druid.query.dimension.DefaultDimensionSpec in project druid by druid-io.
the class CalciteQueryTest method testNvlColumns.
@Test
public void testNvlColumns() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
testQuery("SELECT NVL(dim2, dim1), COUNT(*) FROM druid.foo GROUP BY NVL(dim2, dim1)\n", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "case_searched(notnull(\"dim2\"),\"dim2\",\"dim1\")", ColumnType.STRING)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.STRING))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(QUERY_CONTEXT_DEFAULT).build()), NullHandling.replaceWithDefault() ? ImmutableList.of(new Object[] { "10.1", 1L }, new Object[] { "2", 1L }, new Object[] { "a", 2L }, new Object[] { "abc", 2L }) : ImmutableList.of(new Object[] { "", 1L }, new Object[] { "10.1", 1L }, new Object[] { "a", 2L }, new Object[] { "abc", 2L }));
}
use of org.apache.druid.query.dimension.DefaultDimensionSpec in project druid by druid-io.
the class CalciteQueryTest method testOrderByLatestDouble.
@Test
public void testOrderByLatestDouble() throws Exception {
// Cannot vectorize LATEST aggregator.
skipVectorize();
List<Object[]> expected;
if (NullHandling.replaceWithDefault()) {
expected = ImmutableList.of(new Object[] { "1", 0.0 }, new Object[] { "2", 0.0 }, new Object[] { "abc", 0.0 }, new Object[] { "def", 0.0 }, new Object[] { "", 1.0 }, new Object[] { "10.1", 1.7 });
} else {
expected = ImmutableList.of(new Object[] { "1", null }, new Object[] { "abc", null }, new Object[] { "def", null }, new Object[] { "2", 0.0 }, new Object[] { "", 1.0 }, new Object[] { "10.1", 1.7 });
}
testQuery("SELECT dim1, LATEST(d1) FROM druid.numfoo GROUP BY 1 ORDER BY 2 LIMIT 10", ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("dim1", "_d0")).aggregators(aggregators(new DoubleLastAggregatorFactory("a0", "d1", null))).metric(new InvertedTopNMetricSpec(new NumericTopNMetricSpec("a0"))).threshold(10).context(QUERY_CONTEXT_DEFAULT).build()), expected);
}
use of org.apache.druid.query.dimension.DefaultDimensionSpec in project druid by druid-io.
the class CalciteQueryTest method testGroupByExtractYear.
@Test
public void testGroupByExtractYear() throws Exception {
// Cannot vectorize due to virtual columns.
cannotVectorize();
testQuery("SELECT\n" + " EXTRACT(YEAR FROM __time) AS \"year\",\n" + " SUM(cnt)\n" + "FROM druid.foo\n" + "GROUP BY EXTRACT(YEAR FROM __time)\n" + "ORDER BY 1", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "timestamp_extract(\"__time\",'YEAR','UTC')", ColumnType.LONG)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.LONG))).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d0", OrderByColumnSpec.Direction.ASCENDING, StringComparators.NUMERIC)), Integer.MAX_VALUE)).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 2000L, 3L }, new Object[] { 2001L, 3L }));
}
Aggregations