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 }));
}
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));
}
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());
}
Aggregations