use of org.apache.druid.query.dimension.DefaultDimensionSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueStringWorksLikeStringGroupBy.
// various queries on multi-valued string dimensions using them like strings
@Test
public void testMultiValueStringWorksLikeStringGroupBy() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
Map<String, Object> groupByOnMultiValueColumnEnabled = new HashMap<>(QUERY_CONTEXT_DEFAULT);
groupByOnMultiValueColumnEnabled.put(GroupByQueryConfig.CTX_KEY_ENABLE_MULTI_VALUE_UNNESTING, true);
List<Object[]> expected;
if (NullHandling.replaceWithDefault()) {
expected = ImmutableList.of(new Object[] { "bfoo", 2L }, new Object[] { "foo", 2L }, new Object[] { "", 1L }, new Object[] { "afoo", 1L }, new Object[] { "cfoo", 1L }, new Object[] { "dfoo", 1L });
} else {
expected = ImmutableList.of(new Object[] { null, 2L }, new Object[] { "bfoo", 2L }, new Object[] { "afoo", 1L }, new Object[] { "cfoo", 1L }, new Object[] { "dfoo", 1L }, new Object[] { "foo", 1L });
}
testQuery("SELECT concat(dim3, 'foo'), SUM(cnt) FROM druid.numfoo GROUP BY 1 ORDER BY 2 DESC", groupByOnMultiValueColumnEnabled, ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE3).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "concat(\"dim3\",'foo')", ColumnType.STRING)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "_d0", ColumnType.STRING))).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("a0", OrderByColumnSpec.Direction.DESCENDING, StringComparators.NUMERIC)), Integer.MAX_VALUE)).setContext(QUERY_CONTEXT_DEFAULT).build()), expected);
}
use of org.apache.druid.query.dimension.DefaultDimensionSpec in project druid by druid-io.
the class CalciteQueryTest method testGroupByCaseWhen.
@Test
public void testGroupByCaseWhen() throws Exception {
// Cannot vectorize due to virtual columns.
cannotVectorize();
testQuery("SELECT\n" + " CASE EXTRACT(DAY FROM __time)\n" + " WHEN m1 THEN 'match-m1'\n" + " WHEN cnt THEN 'match-cnt'\n" + " WHEN 0 THEN 'zero'" + " END," + " COUNT(*)\n" + "FROM druid.foo\n" + "GROUP BY" + " CASE EXTRACT(DAY FROM __time)\n" + " WHEN m1 THEN 'match-m1'\n" + " WHEN cnt THEN 'match-cnt'\n" + " WHEN 0 THEN 'zero'" + " END", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "case_searched(" + "(CAST(timestamp_extract(\"__time\",'DAY','UTC'), 'DOUBLE') == \"m1\")," + "'match-m1'," + "(timestamp_extract(\"__time\",'DAY','UTC') == \"cnt\")," + "'match-cnt'," + "(timestamp_extract(\"__time\",'DAY','UTC') == 0)," + "'zero'," + DruidExpression.nullLiteral() + ")", ColumnType.STRING)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "d0"))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { NullHandling.defaultStringValue(), 2L }, new Object[] { "match-cnt", 1L }, new Object[] { "match-m1", 3L }));
}
use of org.apache.druid.query.dimension.DefaultDimensionSpec in project druid by druid-io.
the class CalciteQueryTest method testOrderByEarliestFloat.
@Test
public void testOrderByEarliestFloat() throws Exception {
// Cannot vectorize EARLIEST aggregator.
skipVectorize();
List<Object[]> expected;
if (NullHandling.replaceWithDefault()) {
expected = ImmutableList.of(new Object[] { "1", 0.0f }, new Object[] { "2", 0.0f }, new Object[] { "abc", 0.0f }, new Object[] { "def", 0.0f }, new Object[] { "10.1", 0.1f }, new Object[] { "", 1.0f });
} else {
expected = ImmutableList.of(new Object[] { "1", null }, new Object[] { "abc", null }, new Object[] { "def", null }, new Object[] { "2", 0.0f }, new Object[] { "10.1", 0.1f }, new Object[] { "", 1.0f });
}
testQuery("SELECT dim1, EARLIEST(f1) 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 FloatFirstAggregatorFactory("a0", "f1", 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 testExactCountDistinctUsingSubqueryWithWherePushDown.
@Test
public void testExactCountDistinctUsingSubqueryWithWherePushDown() throws Exception {
testQuery("SELECT\n" + " SUM(cnt),\n" + " COUNT(*)\n" + "FROM (SELECT dim2, SUM(cnt) AS cnt FROM druid.foo GROUP BY dim2)\n" + "WHERE dim2 <> ''", ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setDimFilter(not(selector("dim2", "", null))).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("dim2", "d0"))).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt"))).setContext(QUERY_CONTEXT_DEFAULT).build())).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("_a0", "a0"), new CountAggregatorFactory("_a1"))).setContext(QUERY_CONTEXT_DEFAULT).build()), NullHandling.replaceWithDefault() ? ImmutableList.of(new Object[] { 3L, 2L }) : ImmutableList.of(new Object[] { 5L, 3L }));
testQuery("SELECT\n" + " SUM(cnt),\n" + " COUNT(*)\n" + "FROM (SELECT dim2, SUM(cnt) AS cnt FROM druid.foo GROUP BY dim2)\n" + "WHERE dim2 IS NOT NULL", ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setDimFilter(not(selector("dim2", null, null))).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("dim2", "d0"))).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt"))).setContext(QUERY_CONTEXT_DEFAULT).build())).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("_a0", "a0"), new CountAggregatorFactory("_a1"))).setContext(QUERY_CONTEXT_DEFAULT).build()), NullHandling.replaceWithDefault() ? ImmutableList.of(new Object[] { 3L, 2L }) : ImmutableList.of(new Object[] { 4L, 3L }));
}
use of org.apache.druid.query.dimension.DefaultDimensionSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueStringOffset.
@Test
public void testMultiValueStringOffset() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
testQuery("SELECT MV_OFFSET(dim3, 1), SUM(cnt) FROM druid.numfoo GROUP BY 1 ORDER BY 2 DESC", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE3).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "array_offset(\"dim3\",1)", ColumnType.STRING)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "_d0", ColumnType.STRING))).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("a0", OrderByColumnSpec.Direction.DESCENDING, StringComparators.NUMERIC)), Integer.MAX_VALUE)).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { NullHandling.defaultStringValue(), 4L }, new Object[] { "b", 1L }, new Object[] { "c", 1L }));
}
Aggregations