Search in sources :

Example 36 with SelectorDimFilter

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

the class SearchBenchmark method basicC.

private static SearchQueryBuilder basicC(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, IdentityExtractionFn.getInstance()));
    dimFilters.add(new SelectorDimFilter(dimName, "3", StrlenExtractionFn.instance()));
    dimFilters.add(new BoundDimFilter(dimName, "100", "10000", true, true, true, new DimExtractionFn() {

        @Override
        public byte[] getCacheKey() {
            return new byte[] { 0xF };
        }

        @Override
        public String apply(String value) {
            return String.valueOf(Long.parseLong(value) + 1);
        }

        @Override
        public boolean preservesOrdering() {
            return false;
        }

        @Override
        public ExtractionType getExtractionType() {
            return ExtractionType.ONE_TO_ONE;
        }
    }, null));
    dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, new LowerExtractionFn(null)));
    dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, new UpperExtractionFn(null)));
    dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, new SubstringDimExtractionFn(1, 3)));
    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) MultipleIntervalSegmentSpec(io.druid.query.spec.MultipleIntervalSegmentSpec) SubstringDimExtractionFn(io.druid.query.extraction.SubstringDimExtractionFn) LowerExtractionFn(io.druid.query.extraction.LowerExtractionFn) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) QuerySegmentSpec(io.druid.query.spec.QuerySegmentSpec) 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) DimExtractionFn(io.druid.query.extraction.DimExtractionFn) SubstringDimExtractionFn(io.druid.query.extraction.SubstringDimExtractionFn) UpperExtractionFn(io.druid.query.extraction.UpperExtractionFn)

Example 37 with SelectorDimFilter

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

the class CachingClusteredClientTest method testSingleDimensionPruning.

@Test
public void testSingleDimensionPruning() throws Exception {
    DimFilter filter = Druids.newAndDimFilterBuilder().fields(Arrays.asList(Druids.newOrDimFilterBuilder().fields(Arrays.asList(new SelectorDimFilter("dim1", "a", null), new BoundDimFilter("dim1", "from", "to", false, false, false, null, StringComparators.LEXICOGRAPHIC))).build(), Druids.newAndDimFilterBuilder().fields(Arrays.asList(new InDimFilter("dim2", Arrays.asList("a", "c", "e", "g"), null), new BoundDimFilter("dim2", "aaa", "hi", false, false, false, null, StringComparators.LEXICOGRAPHIC), new BoundDimFilter("dim2", "e", "zzz", true, true, false, null, StringComparators.LEXICOGRAPHIC))).build())).build();
    final Druids.TimeseriesQueryBuilder builder = Druids.newTimeseriesQueryBuilder().dataSource(DATA_SOURCE).filters(filter).granularity(GRANULARITY).intervals(SEG_SPEC).context(CONTEXT).intervals("2011-01-05/2011-01-10").aggregators(RENAMED_AGGS).postAggregators(RENAMED_POST_AGGS);
    TimeseriesQuery query = builder.build();
    Map<String, List> context = new HashMap<>();
    final Interval interval1 = new Interval("2011-01-06/2011-01-07");
    final Interval interval2 = new Interval("2011-01-07/2011-01-08");
    final Interval interval3 = new Interval("2011-01-08/2011-01-09");
    QueryRunner runner = new FinalizeResultsQueryRunner(client, new TimeseriesQueryQueryToolChest(QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator()));
    final DruidServer lastServer = servers[random.nextInt(servers.length)];
    ServerSelector selector1 = makeMockSingleDimensionSelector(lastServer, "dim1", null, "b", 1);
    ServerSelector selector2 = makeMockSingleDimensionSelector(lastServer, "dim1", "e", "f", 2);
    ServerSelector selector3 = makeMockSingleDimensionSelector(lastServer, "dim1", "hi", "zzz", 3);
    ServerSelector selector4 = makeMockSingleDimensionSelector(lastServer, "dim2", "a", "e", 4);
    ServerSelector selector5 = makeMockSingleDimensionSelector(lastServer, "dim2", null, null, 5);
    ServerSelector selector6 = makeMockSingleDimensionSelector(lastServer, "other", "b", null, 6);
    timeline.add(interval1, "v", new StringPartitionChunk<>(null, "a", 1, selector1));
    timeline.add(interval1, "v", new StringPartitionChunk<>("a", "b", 2, selector2));
    timeline.add(interval1, "v", new StringPartitionChunk<>("b", null, 3, selector3));
    timeline.add(interval2, "v", new StringPartitionChunk<>(null, "d", 4, selector4));
    timeline.add(interval2, "v", new StringPartitionChunk<>("d", null, 5, selector5));
    timeline.add(interval3, "v", new StringPartitionChunk<>(null, null, 6, selector6));
    final Capture<TimeseriesQuery> capture = Capture.newInstance();
    final Capture<Map<String, List>> contextCap = Capture.newInstance();
    QueryRunner mockRunner = EasyMock.createNiceMock(QueryRunner.class);
    EasyMock.expect(mockRunner.run(EasyMock.capture(capture), EasyMock.capture(contextCap))).andReturn(Sequences.empty()).anyTimes();
    EasyMock.expect(serverView.getQueryRunner(lastServer)).andReturn(mockRunner).anyTimes();
    EasyMock.replay(serverView);
    EasyMock.replay(mockRunner);
    List<SegmentDescriptor> descriptors = new ArrayList<>();
    descriptors.add(new SegmentDescriptor(interval1, "v", 1));
    descriptors.add(new SegmentDescriptor(interval1, "v", 3));
    descriptors.add(new SegmentDescriptor(interval2, "v", 5));
    descriptors.add(new SegmentDescriptor(interval3, "v", 6));
    MultipleSpecificSegmentSpec expected = new MultipleSpecificSegmentSpec(descriptors);
    Sequences.toList(runner.run(query, context), Lists.newArrayList());
    Assert.assertEquals(expected, capture.getValue().getQuerySegmentSpec());
}
Also used : MultipleSpecificSegmentSpec(io.druid.query.spec.MultipleSpecificSegmentSpec) BoundDimFilter(io.druid.query.filter.BoundDimFilter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TimeseriesQueryQueryToolChest(io.druid.query.timeseries.TimeseriesQueryQueryToolChest) ServerSelector(io.druid.client.selector.ServerSelector) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) SegmentDescriptor(io.druid.query.SegmentDescriptor) Druids(io.druid.query.Druids) InDimFilter(io.druid.query.filter.InDimFilter) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer) FinalizeResultsQueryRunner(io.druid.query.FinalizeResultsQueryRunner) QueryRunner(io.druid.query.QueryRunner) FinalizeResultsQueryRunner(io.druid.query.FinalizeResultsQueryRunner) BoundDimFilter(io.druid.query.filter.BoundDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) Map(java.util.Map) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Interval(org.joda.time.Interval) Test(org.junit.Test) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest)

Example 38 with SelectorDimFilter

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

the class QuantileSqlAggregatorTest method testQuantileOnFloatAndLongs.

@Test
public void testQuantileOnFloatAndLongs() throws Exception {
    try (final DruidPlanner planner = plannerFactory.createPlanner(null)) {
        final String sql = "SELECT\n" + "APPROX_QUANTILE(m1, 0.01),\n" + "APPROX_QUANTILE(m1, 0.5, 50),\n" + "APPROX_QUANTILE(m1, 0.98, 200),\n" + "APPROX_QUANTILE(m1, 0.99),\n" + "APPROX_QUANTILE(m1, 0.99) FILTER(WHERE dim1 = 'abc'),\n" + "APPROX_QUANTILE(m1, 0.999) FILTER(WHERE dim1 <> 'abc'),\n" + "APPROX_QUANTILE(m1, 0.999) FILTER(WHERE dim1 = 'abc'),\n" + "APPROX_QUANTILE(cnt, 0.5)\n" + "FROM foo";
        final PlannerResult plannerResult = planner.plan(sql);
        // Verify results
        final List<Object[]> results = Sequences.toList(plannerResult.run(), new ArrayList<Object[]>());
        final List<Object[]> expectedResults = ImmutableList.of(new Object[] { 1.0, 3.0, 5.880000114440918, 5.940000057220459, 6.0, 4.994999885559082, 6.0, 1.0 });
        Assert.assertEquals(expectedResults.size(), results.size());
        for (int i = 0; i < expectedResults.size(); i++) {
            Assert.assertArrayEquals(expectedResults.get(i), results.get(i));
        }
        // Verify query
        Assert.assertEquals(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new ApproximateHistogramAggregatorFactory("a0:agg", "m1", null, null, null, null), new ApproximateHistogramAggregatorFactory("a2:agg", "m1", 200, null, null, null), new FilteredAggregatorFactory(new ApproximateHistogramAggregatorFactory("a4:agg", "m1", null, null, null, null), new SelectorDimFilter("dim1", "abc", null)), new FilteredAggregatorFactory(new ApproximateHistogramAggregatorFactory("a5:agg", "m1", null, null, null, null), new NotDimFilter(new SelectorDimFilter("dim1", "abc", null))), new ApproximateHistogramAggregatorFactory("a7:agg", "cnt", null, null, null, null))).postAggregators(ImmutableList.<PostAggregator>of(new QuantilePostAggregator("a0", "a0:agg", 0.01f), new QuantilePostAggregator("a1", "a0:agg", 0.50f), new QuantilePostAggregator("a2", "a2:agg", 0.98f), new QuantilePostAggregator("a3", "a0:agg", 0.99f), new QuantilePostAggregator("a4", "a4:agg", 0.99f), new QuantilePostAggregator("a5", "a5:agg", 0.999f), new QuantilePostAggregator("a6", "a4:agg", 0.999f), new QuantilePostAggregator("a7", "a7:agg", 0.50f))).context(ImmutableMap.<String, Object>of("skipEmptyBuckets", true)).build(), Iterables.getOnlyElement(queryLogHook.getRecordedQueries()));
    }
}
Also used : FilteredAggregatorFactory(io.druid.query.aggregation.FilteredAggregatorFactory) NotDimFilter(io.druid.query.filter.NotDimFilter) PostAggregator(io.druid.query.aggregation.PostAggregator) QuantilePostAggregator(io.druid.query.aggregation.histogram.QuantilePostAggregator) QuantilePostAggregator(io.druid.query.aggregation.histogram.QuantilePostAggregator) MultipleIntervalSegmentSpec(io.druid.query.spec.MultipleIntervalSegmentSpec) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DruidPlanner(io.druid.sql.calcite.planner.DruidPlanner) ApproximateHistogramAggregatorFactory(io.druid.query.aggregation.histogram.ApproximateHistogramAggregatorFactory) PlannerResult(io.druid.sql.calcite.planner.PlannerResult) Test(org.junit.Test)

Example 39 with SelectorDimFilter

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

the class FilteredAggregatorTest method testAggregateWithNotFilter.

@Test
public void testAggregateWithNotFilter() {
    final float[] values = { 0.15f, 0.27f };
    final TestFloatColumnSelector selector = new TestFloatColumnSelector(values);
    FilteredAggregatorFactory factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new NotDimFilter(new SelectorDimFilter("dim", "b", null)));
    validateFilteredAggs(factory, values, selector);
}
Also used : NotDimFilter(io.druid.query.filter.NotDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) Test(org.junit.Test)

Example 40 with SelectorDimFilter

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

the class FilteredAggregatorTest method testAggregate.

@Test
public void testAggregate() {
    final float[] values = { 0.15f, 0.27f };
    final TestFloatColumnSelector selector = new TestFloatColumnSelector(values);
    FilteredAggregatorFactory factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new SelectorDimFilter("dim", "a", null));
    FilteredAggregator agg = (FilteredAggregator) factory.factorize(makeColumnSelector(selector));
    double expectedFirst = new Float(values[0]).doubleValue();
    double expectedSecond = new Float(values[1]).doubleValue() + expectedFirst;
    double expectedThird = expectedSecond;
    assertValues(agg, selector, expectedFirst, expectedSecond, expectedThird);
}
Also used : SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) Test(org.junit.Test)

Aggregations

SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)93 Test (org.junit.Test)83 BoundDimFilter (io.druid.query.filter.BoundDimFilter)34 AndDimFilter (io.druid.query.filter.AndDimFilter)26 DimFilter (io.druid.query.filter.DimFilter)25 InDimFilter (io.druid.query.filter.InDimFilter)25 OrDimFilter (io.druid.query.filter.OrDimFilter)23 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)22 Row (io.druid.data.input.Row)21 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)20 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)18 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)18 JavaScriptDimFilter (io.druid.query.filter.JavaScriptDimFilter)16 RegexDimFilter (io.druid.query.filter.RegexDimFilter)16 SearchQueryDimFilter (io.druid.query.filter.SearchQueryDimFilter)16 ArrayList (java.util.ArrayList)16 Result (io.druid.query.Result)12 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)12 DateTime (org.joda.time.DateTime)12 DimensionSpec (io.druid.query.dimension.DimensionSpec)11