use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueToArrayGroupAsArrayWithSingleValueDim.
@Test
public void testMultiValueToArrayGroupAsArrayWithSingleValueDim() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
testQuery("SELECT MV_TO_ARRAY(dim1), SUM(cnt) FROM druid.numfoo GROUP BY 1 ORDER BY 2 DESC", QUERY_CONTEXT_NO_STRINGIFY_ARRAY, ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE3).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "mv_to_array(\"dim1\")", ColumnType.STRING_ARRAY)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "_d0", ColumnType.STRING_ARRAY))).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_NO_STRINGIFY_ARRAY).build()), useDefault ? ImmutableList.of(new Object[] { null, 1L }, new Object[] { ImmutableList.of("1"), 1L }, new Object[] { ImmutableList.of("10.1"), 1L }, new Object[] { ImmutableList.of("2"), 1L }, new Object[] { ImmutableList.of("abc"), 1L }, new Object[] { ImmutableList.of("def"), 1L }) : ImmutableList.of(new Object[] { ImmutableList.of(""), 1L }, new Object[] { ImmutableList.of("1"), 1L }, new Object[] { ImmutableList.of("10.1"), 1L }, new Object[] { ImmutableList.of("2"), 1L }, new Object[] { ImmutableList.of("abc"), 1L }, new Object[] { ImmutableList.of("def"), 1L }));
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueStringOrdinal.
@Test
public void testMultiValueStringOrdinal() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
testQuery("SELECT MV_ORDINAL(dim3, 2), 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_ordinal(\"dim3\",2)", 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 }));
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueToArrayGroupAsArrayWithSingleValueDimIsNotConvertedToTopN.
@Test
public void testMultiValueToArrayGroupAsArrayWithSingleValueDimIsNotConvertedToTopN() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
// Test for method {@link org.apache.druid.sql.calcite.rel.DruidQuery.toTopNQuery()} so that it does not convert
// group by on array to topn
testQuery("SELECT MV_TO_ARRAY(dim1), SUM(cnt) FROM druid.numfoo GROUP BY 1 ORDER BY 2 DESC limit 10", QUERY_CONTEXT_NO_STRINGIFY_ARRAY, ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE3).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "mv_to_array(\"dim1\")", ColumnType.STRING_ARRAY)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "_d0", ColumnType.STRING_ARRAY))).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("a0", OrderByColumnSpec.Direction.DESCENDING, StringComparators.NUMERIC)), 10)).setContext(QUERY_CONTEXT_NO_STRINGIFY_ARRAY).build()), useDefault ? ImmutableList.of(new Object[] { null, 1L }, new Object[] { ImmutableList.of("1"), 1L }, new Object[] { ImmutableList.of("10.1"), 1L }, new Object[] { ImmutableList.of("2"), 1L }, new Object[] { ImmutableList.of("abc"), 1L }, new Object[] { ImmutableList.of("def"), 1L }) : ImmutableList.of(new Object[] { ImmutableList.of(""), 1L }, new Object[] { ImmutableList.of("1"), 1L }, new Object[] { ImmutableList.of("10.1"), 1L }, new Object[] { ImmutableList.of("2"), 1L }, new Object[] { ImmutableList.of("abc"), 1L }, new Object[] { ImmutableList.of("def"), 1L }));
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueStringConcat.
@Test
public void testMultiValueStringConcat() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
ImmutableList<Object[]> results;
if (useDefault) {
results = ImmutableList.of(new Object[] { "b", 4L }, new Object[] { "", 3L }, new Object[] { "a", 2L }, new Object[] { "c", 2L }, new Object[] { "d", 2L });
} else {
results = ImmutableList.of(new Object[] { "b", 4L }, new Object[] { null, 2L }, new Object[] { "", 2L }, new Object[] { "a", 2L }, new Object[] { "c", 2L }, new Object[] { "d", 2L });
}
testQuery("SELECT MV_CONCAT(dim3, dim3), 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_concat(\"dim3\",\"dim3\")", 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()), results);
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueStringWorksLikeStringGroupByWithFilter.
@Test
public void testMultiValueStringWorksLikeStringGroupByWithFilter() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
testQuery("SELECT concat(dim3, 'foo'), SUM(cnt) FROM druid.numfoo where concat(dim3, 'foo') = 'bfoo' GROUP BY 1 ORDER BY 2 DESC", 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))).setDimFilter(selector("v0", "bfoo", null)).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[] { "bfoo", 2L }, new Object[] { "afoo", 1L }, new Object[] { "cfoo", 1L }));
}
Aggregations