Search in sources :

Example 41 with DimFilter

use of io.druid.query.filter.DimFilter 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));
}
Also used : BoundDimFilter(io.druid.query.filter.BoundDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) QuerySegmentSpec(io.druid.query.spec.QuerySegmentSpec) MultipleIntervalSegmentSpec(io.druid.query.spec.MultipleIntervalSegmentSpec) BoundDimFilter(io.druid.query.filter.BoundDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter)

Example 42 with DimFilter

use of io.druid.query.filter.DimFilter in project druid by druid-io.

the class TimeseriesBenchmark method queryFilteredSingleQueryableIndex.

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void queryFilteredSingleQueryableIndex(Blackhole blackhole) throws Exception {
    final QueryRunner<Result<TimeseriesResultValue>> runner = QueryBenchmarkUtil.makeQueryRunner(factory, "qIndex", new QueryableIndexSegment("qIndex", qIndexes.get(0)));
    DimFilter filter = new SelectorDimFilter("dimSequential", "399", null);
    Query filteredQuery = query.withDimFilter(filter);
    List<Result<TimeseriesResultValue>> results = TimeseriesBenchmark.runQuery(factory, runner, filteredQuery);
    for (Result<TimeseriesResultValue> result : results) {
        blackhole.consume(result);
    }
}
Also used : QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) TimeseriesResultValue(io.druid.query.timeseries.TimeseriesResultValue) TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) Query(io.druid.query.Query) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) BoundDimFilter(io.druid.query.filter.BoundDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) Result(io.druid.query.Result) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 43 with DimFilter

use of io.druid.query.filter.DimFilter in project druid by druid-io.

the class AndFilterTest method testAnd.

@Test
public void testAnd() {
    assertFilterMatches(new AndDimFilter(ImmutableList.<DimFilter>of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "0", null))), ImmutableList.of("0"));
    assertFilterMatches(new AndDimFilter(ImmutableList.<DimFilter>of(new SelectorDimFilter("dim0", "0", null), new SelectorDimFilter("dim1", "1", null))), ImmutableList.<String>of());
    assertFilterMatches(new AndDimFilter(ImmutableList.<DimFilter>of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "0", null))), ImmutableList.of("1"));
    assertFilterMatches(new AndDimFilter(ImmutableList.<DimFilter>of(new SelectorDimFilter("dim0", "1", null), new SelectorDimFilter("dim1", "1", null))), ImmutableList.<String>of());
    assertFilterMatches(new AndDimFilter(ImmutableList.<DimFilter>of(new NotDimFilter(new SelectorDimFilter("dim0", "1", null)), new NotDimFilter(new SelectorDimFilter("dim1", "1", null)))), ImmutableList.of("0", "2", "3", "4", "5"));
    assertFilterMatches(new AndDimFilter(ImmutableList.<DimFilter>of(new NotDimFilter(new SelectorDimFilter("dim0", "0", null)), new NotDimFilter(new SelectorDimFilter("dim1", "0", null)))), ImmutableList.<String>of());
}
Also used : NotDimFilter(io.druid.query.filter.NotDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) NotDimFilter(io.druid.query.filter.NotDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) Test(org.junit.Test)

Example 44 with DimFilter

use of io.druid.query.filter.DimFilter in project druid by druid-io.

the class BaseFilterTest method makeFilter.

private Filter makeFilter(final DimFilter dimFilter) {
    if (dimFilter == null) {
        return null;
    }
    final DimFilter maybeOptimized = optimize ? dimFilter.optimize() : dimFilter;
    final Filter filter = maybeOptimized.toFilter();
    return cnf ? Filters.convertToCNF(filter) : filter;
}
Also used : DimFilter(io.druid.query.filter.DimFilter) Filter(io.druid.query.filter.Filter) DimFilter(io.druid.query.filter.DimFilter)

Example 45 with DimFilter

use of io.druid.query.filter.DimFilter in project druid by druid-io.

the class BaseFilterTest method selectColumnValuesMatchingFilterUsingPostFiltering.

private List<String> selectColumnValuesMatchingFilterUsingPostFiltering(final DimFilter filter, final String selectColumn) {
    final Filter theFilter = makeFilter(filter);
    final Filter postFilteringFilter = new Filter() {

        @Override
        public ImmutableBitmap getBitmapIndex(BitmapIndexSelector selector) {
            throw new UnsupportedOperationException();
        }

        @Override
        public ValueMatcher makeMatcher(ColumnSelectorFactory factory) {
            return theFilter.makeMatcher(factory);
        }

        @Override
        public boolean supportsBitmapIndex(BitmapIndexSelector selector) {
            return false;
        }

        @Override
        public boolean supportsSelectivityEstimation(ColumnSelector columnSelector, BitmapIndexSelector indexSelector) {
            return false;
        }

        @Override
        public double estimateSelectivity(BitmapIndexSelector indexSelector) {
            return 1.0;
        }
    };
    final Sequence<Cursor> cursors = makeCursorSequence(postFilteringFilter);
    Sequence<List<String>> seq = Sequences.map(cursors, new Function<Cursor, List<String>>() {

        @Override
        public List<String> apply(Cursor input) {
            final DimensionSelector selector = input.makeDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
            final List<String> values = Lists.newArrayList();
            while (!input.isDone()) {
                IndexedInts row = selector.getRow();
                Preconditions.checkState(row.size() == 1);
                values.add(selector.lookupName(row.get(0)));
                input.advance();
            }
            return values;
        }
    });
    return Sequences.toList(seq, new ArrayList<List<String>>()).get(0);
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) RowBasedColumnSelectorFactory(io.druid.query.groupby.RowBasedColumnSelectorFactory) ColumnSelectorFactory(io.druid.segment.ColumnSelectorFactory) ArrayList(java.util.ArrayList) Cursor(io.druid.segment.Cursor) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) DimFilter(io.druid.query.filter.DimFilter) Filter(io.druid.query.filter.Filter) ColumnSelector(io.druid.segment.ColumnSelector) IndexedInts(io.druid.segment.data.IndexedInts) BitmapIndexSelector(io.druid.query.filter.BitmapIndexSelector) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

DimFilter (io.druid.query.filter.DimFilter)56 AndDimFilter (io.druid.query.filter.AndDimFilter)45 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)39 Test (org.junit.Test)32 BoundDimFilter (io.druid.query.filter.BoundDimFilter)30 OrDimFilter (io.druid.query.filter.OrDimFilter)27 InDimFilter (io.druid.query.filter.InDimFilter)24 NotDimFilter (io.druid.query.filter.NotDimFilter)19 RegexDimFilter (io.druid.query.filter.RegexDimFilter)18 Result (io.druid.query.Result)14 ExtractionDimFilter (io.druid.query.filter.ExtractionDimFilter)14 DateTime (org.joda.time.DateTime)14 JavaScriptDimFilter (io.druid.query.filter.JavaScriptDimFilter)11 SearchQueryDimFilter (io.druid.query.filter.SearchQueryDimFilter)11 List (java.util.List)11 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)10 ArrayList (java.util.ArrayList)9 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)8 DimensionSpec (io.druid.query.dimension.DimensionSpec)7 Row (io.druid.data.input.Row)6