use of org.apache.druid.query.groupby.orderby.DefaultLimitSpec 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.DefaultLimitSpec 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.DefaultLimitSpec 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 }));
}
use of org.apache.druid.query.groupby.orderby.DefaultLimitSpec in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testMultiValueListFilterDeny.
@Test
public void testMultiValueListFilterDeny() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
testQuery("SELECT MV_FILTER_NONE(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"), false)).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()), useDefault ? ImmutableList.of(new Object[] { NullHandling.defaultStringValue(), 3L }, new Object[] { "a", 1L }, new Object[] { "c", 1L }, new Object[] { "d", 1L }) : ImmutableList.of(new Object[] { NullHandling.defaultStringValue(), 2L }, new Object[] { "", 1L }, new Object[] { "a", 1L }, new Object[] { "c", 1L }, new Object[] { "d", 1L }));
}
use of org.apache.druid.query.groupby.orderby.DefaultLimitSpec in project druid by druid-io.
the class CalciteQueryTest method testGroupByFormatYearAndMonth.
@Test
public void testGroupByFormatYearAndMonth() throws Exception {
// Cannot vectorize due to virtual columns.
cannotVectorize();
testQuery("SELECT\n" + " TIME_FORMAt(__time, 'yyyy MM') AS \"year\",\n" + " SUM(cnt)\n" + "FROM druid.foo\n" + "GROUP BY TIME_FORMAt(__time, 'yyyy MM')\n" + "ORDER BY 1", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "timestamp_format(\"__time\",'yyyy MM','UTC')", ColumnType.STRING)).setDimensions(dimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.STRING))).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d0", OrderByColumnSpec.Direction.ASCENDING, StringComparators.LEXICOGRAPHIC)), Integer.MAX_VALUE)).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "2000 01", 3L }, new Object[] { "2001 01", 3L }));
}
Aggregations