Search in sources :

Example 6 with ExpressionDimFilter

use of org.apache.druid.query.filter.ExpressionDimFilter in project druid by druid-io.

the class BloomDimFilterSqlTest method testBloomFilterExprFilter.

@Test
public void testBloomFilterExprFilter() throws Exception {
    BloomKFilter filter = new BloomKFilter(1500);
    filter.addString("a-foo");
    filter.addString("-foo");
    if (!NullHandling.replaceWithDefault()) {
        filter.addBytes(null, 0, 0);
    }
    byte[] bytes = BloomFilterSerializersModule.bloomKFilterToBytes(filter);
    String base64 = StringUtils.encodeBase64String(bytes);
    // fool the planner to make an expression virtual column to test bloom filter Druid expression
    testQuery(StringUtils.format("SELECT COUNT(*) FROM druid.foo WHERE nullif(bloom_filter_test(concat(dim2, '-foo'), '%s'), 1) is null", base64), ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).filters(new ExpressionDimFilter(StringUtils.format("case_searched(bloom_filter_test(concat(\"dim2\",'-foo'),'%s'),1,isnull(bloom_filter_test(concat(\"dim2\",'-foo'),'%s')))", base64, base64), null, createMacroTable())).aggregators(aggregators(new CountAggregatorFactory("a0"))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 5L }));
}
Also used : CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 7 with ExpressionDimFilter

use of org.apache.druid.query.filter.ExpressionDimFilter in project druid by druid-io.

the class ExpressionFilterBenchmark method setup.

@Setup(Level.Trial)
public void setup() {
    this.closer = Closer.create();
    final GeneratorSchemaInfo schemaInfo = new GeneratorSchemaInfo(ImmutableList.of(GeneratorColumnSchema.makeEnumerated("x", ValueType.STRING, false, 3, null, Arrays.asList("Apple", "Orange", "Xylophone", "Corundum", null), Arrays.asList(0.2, 0.25, 0.15, 0.10, 0.3)), GeneratorColumnSchema.makeEnumerated("y", ValueType.STRING, false, 4, null, Arrays.asList("Hello", "World", "Foo", "Bar", "Baz"), Arrays.asList(0.2, 0.25, 0.15, 0.10, 0.3))), ImmutableList.of(), Intervals.of("2000/P1D"), false);
    final DataSegment dataSegment = DataSegment.builder().dataSource("foo").interval(schemaInfo.getDataInterval()).version("1").shardSpec(new LinearShardSpec(0)).size(0).build();
    final SegmentGenerator segmentGenerator = closer.register(new SegmentGenerator());
    this.index = closer.register(segmentGenerator.generate(dataSegment, schemaInfo, Granularities.NONE, rowsPerSegment));
    expressionFilter = new ExpressionDimFilter("array_contains(x, ['Orange', 'Xylophone'])", TestExprMacroTable.INSTANCE);
    nativeFilter = new AndDimFilter(new SelectorDimFilter("x", "Orange", null), new SelectorDimFilter("x", "Xylophone", null));
}
Also used : SegmentGenerator(org.apache.druid.segment.generator.SegmentGenerator) AndDimFilter(org.apache.druid.query.filter.AndDimFilter) LinearShardSpec(org.apache.druid.timeline.partition.LinearShardSpec) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) GeneratorSchemaInfo(org.apache.druid.segment.generator.GeneratorSchemaInfo) DataSegment(org.apache.druid.timeline.DataSegment) ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter) Setup(org.openjdk.jmh.annotations.Setup)

Example 8 with ExpressionDimFilter

use of org.apache.druid.query.filter.ExpressionDimFilter in project druid by druid-io.

the class NotFilterTest method testRequiredColumnRewrite.

@Test
public void testRequiredColumnRewrite() {
    Filter filter = new NotFilter(new SelectorFilter("dim0", "B"));
    Filter filter2 = new NotFilter(new SelectorFilter("dim1", "B"));
    Assert.assertTrue(filter.supportsRequiredColumnRewrite());
    Assert.assertTrue(filter2.supportsRequiredColumnRewrite());
    Filter rewrittenFilter = filter.rewriteRequiredColumns(ImmutableMap.of("dim0", "dim1"));
    Assert.assertEquals(filter2, rewrittenFilter);
    Filter filter3 = new NotFilter(new ExpressionDimFilter("dim0 == 'B'", ExprMacroTable.nil()).toFilter());
    Assert.assertFalse(filter3.supportsRequiredColumnRewrite());
}
Also used : ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter) Filter(org.apache.druid.query.filter.Filter) ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter) Test(org.junit.Test)

Aggregations

ExpressionDimFilter (org.apache.druid.query.filter.ExpressionDimFilter)8 Test (org.junit.Test)6 Filter (org.apache.druid.query.filter.Filter)4 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)3 SelectorFilter (org.apache.druid.segment.filter.SelectorFilter)3 JoinFilterPreAnalysis (org.apache.druid.segment.join.filter.JoinFilterPreAnalysis)3 QueryDataSource (org.apache.druid.query.QueryDataSource)2 TableDataSource (org.apache.druid.query.TableDataSource)2 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)2 ExpressionLambdaAggregatorFactory (org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory)2 OrDimFilter (org.apache.druid.query.filter.OrDimFilter)2 IndexedTableJoinable (org.apache.druid.segment.join.table.IndexedTableJoinable)2 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)1 AndDimFilter (org.apache.druid.query.filter.AndDimFilter)1 BloomKFilter (org.apache.druid.query.filter.BloomKFilter)1 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)1 InDimFilter (org.apache.druid.query.filter.InDimFilter)1 VirtualColumn (org.apache.druid.segment.VirtualColumn)1 AndFilter (org.apache.druid.segment.filter.AndFilter)1 BoundFilter (org.apache.druid.segment.filter.BoundFilter)1