use of io.druid.query.filter.InDimFilter in project druid by druid-io.
the class IncrementalIndexReadBenchmark method readWithFilters.
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void readWithFilters(Blackhole blackhole) throws Exception {
DimFilter filter = new OrDimFilter(Arrays.asList(new BoundDimFilter("dimSequential", "-1", "-1", true, true, null, null, StringComparators.ALPHANUMERIC), new JavaScriptDimFilter("dimSequential", "function(x) { return false }", null, JavaScriptConfig.getEnabledInstance()), new RegexDimFilter("dimSequential", "X", null), new SearchQueryDimFilter("dimSequential", new ContainsSearchQuerySpec("X", false), null), new InDimFilter("dimSequential", Arrays.asList("X"), null)));
IncrementalIndexStorageAdapter sa = new IncrementalIndexStorageAdapter(incIndex);
Sequence<Cursor> cursors = makeCursors(sa, filter);
Cursor cursor = Sequences.toList(Sequences.limit(cursors, 1), Lists.<Cursor>newArrayList()).get(0);
List<DimensionSelector> selectors = new ArrayList<>();
selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimSequential", null)));
selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimZipf", null)));
selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimUniform", null)));
selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimSequentialHalfNull", null)));
cursor.reset();
while (!cursor.isDone()) {
for (DimensionSelector selector : selectors) {
IndexedInts row = selector.getRow();
blackhole.consume(selector.lookupName(row.get(0)));
}
cursor.advance();
}
}
use of io.druid.query.filter.InDimFilter in project druid by druid-io.
the class SearchBenchmark method basicD.
private static SearchQueryBuilder basicD(final BenchmarkSchemaInfo basicSchema) {
final QuerySegmentSpec intervalSpec = new MultipleIntervalSegmentSpec(Arrays.asList(basicSchema.getDataInterval()));
final List<String> dimUniformFilterVals = Lists.newArrayList();
final int resultNum = (int) (100000 * 0.1);
final int step = 100000 / resultNum;
for (int i = 1; i < 100001 && dimUniformFilterVals.size() < resultNum; i += step) {
dimUniformFilterVals.add(String.valueOf(i));
}
final String dimName = "dimUniform";
final List<DimFilter> dimFilters = Lists.newArrayList();
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, null));
dimFilters.add(new SelectorDimFilter(dimName, "3", null));
dimFilters.add(new BoundDimFilter(dimName, "100", "10000", true, true, true, null, null));
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, null));
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, null));
dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, null));
return Druids.newSearchQueryBuilder().dataSource("blah").granularity(Granularities.ALL).intervals(intervalSpec).query("").dimensions(Lists.newArrayList("dimUniform")).filters(new AndDimFilter(dimFilters));
}
use of io.druid.query.filter.InDimFilter in project druid by druid-io.
the class TimeFilteringTest method testTimeFilterWithExtractionFn.
@Test
public void testTimeFilterWithExtractionFn() {
final Map<String, String> stringMap = new HashMap<>();
stringMap.put("0", "Monday");
stringMap.put("1", "Tuesday");
stringMap.put("2", "Wednesday");
stringMap.put("3", "Thursday");
stringMap.put("4", "Friday");
stringMap.put("5", "Saturday");
LookupExtractor mapExtractor = new MapLookupExtractor(stringMap, false);
LookupExtractionFn exfn = new LookupExtractionFn(mapExtractor, false, "UNKNOWN", false, true);
assertFilterMatches(new SelectorDimFilter(Column.TIME_COLUMN_NAME, "Monday", exfn), ImmutableList.<String>of("0"));
assertFilterMatches(new SelectorDimFilter(Column.TIME_COLUMN_NAME, "Notaday", exfn), ImmutableList.<String>of());
assertFilterMatches(new BoundDimFilter(Column.TIME_COLUMN_NAME, "Fridax", "Fridaz", false, false, null, exfn, StringComparators.ALPHANUMERIC), ImmutableList.<String>of("4"));
assertFilterMatches(new BoundDimFilter(Column.TIME_COLUMN_NAME, "Friday", "Friday", true, true, null, exfn, StringComparators.ALPHANUMERIC), ImmutableList.<String>of());
assertFilterMatches(new InDimFilter(Column.TIME_COLUMN_NAME, Arrays.asList("Caturday", "Saturday", "Tuesday"), exfn), ImmutableList.<String>of("1", "5"));
// test InFilter HashSet implementation
List<String> bigList = Arrays.asList("Saturday", "Tuesday", "Caturday", "Xanaday", "Vojuday", "Gribaday", "Kipoday", "Dheferday", "Fakeday", "Qeearaday", "Hello", "World", "1", "2", "3", "4", "5", "6", "7");
assertFilterMatches(new InDimFilter(Column.TIME_COLUMN_NAME, bigList, exfn), ImmutableList.<String>of("1", "5"));
String jsFn = "function(x) { return(x === 'Wednesday' || x === 'Thursday') }";
assertFilterMatches(new JavaScriptDimFilter(Column.TIME_COLUMN_NAME, jsFn, exfn, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("2", "3"));
assertFilterMatches(new RegexDimFilter(Column.TIME_COLUMN_NAME, ".*day", exfn), ImmutableList.<String>of("0", "1", "2", "3", "4", "5"));
assertFilterMatches(new SearchQueryDimFilter(Column.TIME_COLUMN_NAME, new ContainsSearchQuerySpec("s", true), exfn), ImmutableList.<String>of("1", "2", "3"));
}
use of io.druid.query.filter.InDimFilter in project druid by druid-io.
the class TimeFilteringTest method testTimeFilterAsLong.
@Test
public void testTimeFilterAsLong() {
assertFilterMatches(new SelectorDimFilter(Column.TIME_COLUMN_NAME, "0", null), ImmutableList.<String>of("0"));
assertFilterMatches(new SelectorDimFilter(Column.TIME_COLUMN_NAME, "9000", null), ImmutableList.<String>of());
assertFilterMatches(new BoundDimFilter(Column.TIME_COLUMN_NAME, "0", "4", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("0", "1", "2", "3", "4"));
assertFilterMatches(new BoundDimFilter(Column.TIME_COLUMN_NAME, "0", "4", true, true, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("1", "2", "3"));
assertFilterMatches(new InDimFilter(Column.TIME_COLUMN_NAME, Arrays.asList("2", "4", "8"), null), ImmutableList.<String>of("2", "4"));
// cross the hashing threshold to test hashset implementation, filter on even values
List<String> infilterValues = new ArrayList<>(InDimFilter.NUMERIC_HASHING_THRESHOLD * 2);
for (int i = 0; i < InDimFilter.NUMERIC_HASHING_THRESHOLD * 2; i++) {
infilterValues.add(String.valueOf(i * 2));
}
assertFilterMatches(new InDimFilter(Column.TIME_COLUMN_NAME, infilterValues, null), ImmutableList.<String>of("0", "2", "4"));
String jsFn = "function(x) { return(x === 3 || x === 5) }";
assertFilterMatches(new JavaScriptDimFilter(Column.TIME_COLUMN_NAME, jsFn, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("3", "5"));
assertFilterMatches(new RegexDimFilter(Column.TIME_COLUMN_NAME, "4", null), ImmutableList.<String>of("4"));
assertFilterMatches(new SearchQueryDimFilter(Column.TIME_COLUMN_NAME, new ContainsSearchQuerySpec("2", true), null), ImmutableList.<String>of("2"));
}
use of io.druid.query.filter.InDimFilter in project druid by druid-io.
the class FloatFilteringTest method testFloatColumnFiltering.
@Test
public void testFloatColumnFiltering() {
assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "0", null), ImmutableList.<String>of());
assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "0.0", null), ImmutableList.<String>of());
assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "3", null), ImmutableList.<String>of("3"));
assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "3.0", null), ImmutableList.<String>of("3"));
assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "2", "5", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3", "4", "5"));
assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "2.0", "5.0", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3", "4", "5"));
assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "1", "4", true, true, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3"));
assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "1.0", "4.0", true, true, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3"));
assertFilterMatches(new InDimFilter(FLOAT_COLUMN, Arrays.asList("2", "4", "8"), null), ImmutableList.<String>of("2", "4"));
assertFilterMatches(new InDimFilter(FLOAT_COLUMN, Arrays.asList("2.0", "4.0", "8.0"), null), ImmutableList.<String>of("2", "4"));
// cross the hashing threshold to test hashset implementation, filter on even values
List<String> infilterValues = new ArrayList<>(InDimFilter.NUMERIC_HASHING_THRESHOLD * 2);
for (int i = 0; i < InDimFilter.NUMERIC_HASHING_THRESHOLD * 2; i++) {
infilterValues.add(String.valueOf(i * 2));
}
assertFilterMatches(new InDimFilter(FLOAT_COLUMN, infilterValues, null), ImmutableList.<String>of("2", "4", "6"));
String jsFn = "function(x) { return(x === 3 || x === 5) }";
assertFilterMatches(new JavaScriptDimFilter(FLOAT_COLUMN, jsFn, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("3", "5"));
String jsFn2 = "function(x) { return(x === 3.0 || x === 5.0) }";
assertFilterMatches(new JavaScriptDimFilter(FLOAT_COLUMN, jsFn2, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("3", "5"));
assertFilterMatches(new RegexDimFilter(FLOAT_COLUMN, "4", null), ImmutableList.<String>of("4"));
assertFilterMatches(new RegexDimFilter(FLOAT_COLUMN, "4.0", null), ImmutableList.<String>of("4"));
assertFilterMatches(new SearchQueryDimFilter(FLOAT_COLUMN, new ContainsSearchQuerySpec("2", true), null), ImmutableList.<String>of("2"));
assertFilterMatches(new SearchQueryDimFilter(FLOAT_COLUMN, new ContainsSearchQuerySpec("2", true), null), ImmutableList.<String>of("2"));
}
Aggregations