use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueStringConcatBackwardsCompat0dot22andOlder.
@Test
public void testMultiValueStringConcatBackwardsCompat0dot22andOlder() throws Exception {
try {
ExpressionProcessing.initializeForHomogenizeNullMultiValueStrings();
// Cannot vectorize due to usage of expressions.
cannotVectorize();
ImmutableList<Object[]> results;
if (useDefault) {
results = ImmutableList.of(new Object[] { "", 6L }, new Object[] { "b", 4L }, new Object[] { "a", 2L }, new Object[] { "c", 2L }, new Object[] { "d", 2L });
} else {
results = ImmutableList.of(new Object[] { null, 4L }, new Object[] { "b", 4L }, 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);
} finally {
ExpressionProcessing.initializeForTests(null);
}
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueListFilterComposed.
@Test
public void testMultiValueListFilterComposed() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
testQuery("SELECT MV_LENGTH(MV_FILTER_ONLY(dim3, ARRAY['b'])), 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_length(\"v1\")", ColumnType.LONG), new ListFilteredVirtualColumn("v1", DefaultDimensionSpec.of("dim3"), ImmutableSet.of("b"), true)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "_d0", ColumnType.LONG))).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()), useDefault ? ImmutableList.of(new Object[] { 0, 4L }, new Object[] { 1, 2L }) : ImmutableList.of(// selector, which treats a 0 length array as null instead of an empty array like is produced by filter
new Object[] { null, 4L }, new Object[] { 1, 2L }));
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueStringPrepend.
@Test
public void testMultiValueStringPrepend() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
ImmutableList<Object[]> results;
if (useDefault) {
results = ImmutableList.of(new Object[] { "", 3L }, new Object[] { "foo", 3L }, new Object[] { "b", 2L }, new Object[] { "a", 1L }, new Object[] { "c", 1L }, new Object[] { "d", 1L });
} else {
results = ImmutableList.of(new Object[] { "foo", 4L }, new Object[] { null, 2L }, new Object[] { "b", 2L }, new Object[] { "", 1L }, new Object[] { "a", 1L }, new Object[] { "c", 1L }, new Object[] { "d", 1L });
}
testQuery("SELECT MV_PREPEND('foo', 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_prepend('foo',\"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 testMultiValueToArrayGroupAsArrayWithMultiValueDimension.
@Test
public void testMultiValueToArrayGroupAsArrayWithMultiValueDimension() throws Exception {
// Cannot vectorize as we donot have support in native query subsytem for grouping on arrays as keys
cannotVectorize();
testQuery("SELECT MV_TO_ARRAY(dim3), 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(\"dim3\")", 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, 3L }, new Object[] { ImmutableList.of("a", "b"), 1L }, new Object[] { ImmutableList.of("b", "c"), 1L }, new Object[] { ImmutableList.of("d"), 1L }) : ImmutableList.of(new Object[] { null, 2L }, new Object[] { ImmutableList.of(""), 1L }, new Object[] { ImmutableList.of("a", "b"), 1L }, new Object[] { ImmutableList.of("b", "c"), 1L }, new Object[] { ImmutableList.of("d"), 1L }));
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueListFilter.
@Test
public void testMultiValueListFilter() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
testQuery("SELECT MV_FILTER_ONLY(dim3, ARRAY['b']), 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(new ListFilteredVirtualColumn("v0", DefaultDimensionSpec.of("dim3"), ImmutableSet.of("b"), true)).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", 2L }));
}
Aggregations