Search in sources :

Example 1 with ListFilteredVirtualColumn

use of org.apache.druid.segment.virtual.ListFilteredVirtualColumn in project druid by druid-io.

the class CalciteMultiValueStringQueryTest method testFilterOnMultiValueListFilterMatchLike.

@Test
public void testFilterOnMultiValueListFilterMatchLike() throws Exception {
    // Cannot vectorize due to usage of expressions.
    cannotVectorize();
    testQuery("SELECT dim3, SUM(cnt) FROM druid.numfoo WHERE MV_FILTER_ONLY(dim3, ARRAY['b']) LIKE 'b%' 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)).setDimFilter(new LikeDimFilter("v0", "b%", null, null)).setDimensions(dimensions(new DefaultDimensionSpec("dim3", "_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[] { "b", 2L }, new Object[] { "a", 1L }, new Object[] { "c", 1L }));
}
Also used : OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ListFilteredVirtualColumn(org.apache.druid.segment.virtual.ListFilteredVirtualColumn) LikeDimFilter(org.apache.druid.query.filter.LikeDimFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 2 with ListFilteredVirtualColumn

use of org.apache.druid.segment.virtual.ListFilteredVirtualColumn in project druid by druid-io.

the class CalciteMultiValueStringQueryTest method testFilterOnMultiValueListFilterNoMatch.

@Test
public void testFilterOnMultiValueListFilterNoMatch() throws Exception {
    // Cannot vectorize due to usage of expressions.
    cannotVectorize();
    testQuery("SELECT dim3, SUM(cnt) FROM druid.numfoo WHERE MV_FILTER_ONLY(dim3, ARRAY['b']) = 'a' 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)).setDimFilter(selector("v0", "a", null)).setDimensions(dimensions(new DefaultDimensionSpec("dim3", "_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());
}
Also used : OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ListFilteredVirtualColumn(org.apache.druid.segment.virtual.ListFilteredVirtualColumn) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 3 with ListFilteredVirtualColumn

use of org.apache.druid.segment.virtual.ListFilteredVirtualColumn in project druid by druid-io.

the class CalciteMultiValueStringQueryTest method testMultiValueListFilterComposedDeny.

@Test
public void testMultiValueListFilterComposedDeny() throws Exception {
    // Cannot vectorize due to usage of expressions.
    cannotVectorize();
    testQuery("SELECT MV_LENGTH(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(expressionVirtualColumn("v0", "array_length(\"v1\")", ColumnType.LONG), new ListFilteredVirtualColumn("v1", DefaultDimensionSpec.of("dim3"), ImmutableSet.of("b"), false)).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, 3L }, new Object[] { 1, 3L }) : ImmutableList.of(new Object[] { 1, 4L }, new Object[] { null, 2L }));
}
Also used : OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ListFilteredVirtualColumn(org.apache.druid.segment.virtual.ListFilteredVirtualColumn) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 4 with ListFilteredVirtualColumn

use of org.apache.druid.segment.virtual.ListFilteredVirtualColumn 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 }));
}
Also used : OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ListFilteredVirtualColumn(org.apache.druid.segment.virtual.ListFilteredVirtualColumn) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 5 with ListFilteredVirtualColumn

use of org.apache.druid.segment.virtual.ListFilteredVirtualColumn 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 }));
}
Also used : OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ListFilteredVirtualColumn(org.apache.druid.segment.virtual.ListFilteredVirtualColumn) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)7 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)7 DefaultLimitSpec (org.apache.druid.query.groupby.orderby.DefaultLimitSpec)7 OrderByColumnSpec (org.apache.druid.query.groupby.orderby.OrderByColumnSpec)7 ListFilteredVirtualColumn (org.apache.druid.segment.virtual.ListFilteredVirtualColumn)7 Test (org.junit.Test)7 LikeDimFilter (org.apache.druid.query.filter.LikeDimFilter)1