Search in sources :

Example 26 with AndDimFilter

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

the class FilterPartitionTest method testBasicPreAndPostFilterWithNulls.

@Test
public void testBasicPreAndPostFilterWithNulls() {
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim2", "a", null), new NoBitmapSelectorDimFilter("dim1", null, null))), ImmutableList.of("0"));
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "10", null), new NoBitmapSelectorDimFilter("dim2", null, null))), ImmutableList.of("1"));
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "1", null), new NoBitmapSelectorDimFilter("dim2", "foo", null))), ImmutableList.of("9"));
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "HELLO", null), new NoBitmapSelectorDimFilter("dim2", "bar", null))), ImmutableList.<String>of());
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new NoBitmapSelectorDimFilter("dim2", "bar", null), new SelectorDimFilter("dim1", "NOT_A_VALUE", null))), ImmutableList.<String>of());
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim2", "super-a", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim1", "super-null", JS_EXTRACTION_FN))), ImmutableList.of("0"));
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "super-10", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim2", "super-null", JS_EXTRACTION_FN))), ImmutableList.of("1"));
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "super-2", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim2", "super-null", JS_EXTRACTION_FN))), ImmutableList.of("2"));
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "super-1", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim2", "super-foo", JS_EXTRACTION_FN))), ImmutableList.of("9"));
    assertFilterMatches(new AndDimFilter(Arrays.<DimFilter>asList(new SelectorDimFilter("dim1", "super-HELLO", JS_EXTRACTION_FN), new NoBitmapSelectorDimFilter("dim2", "super-bar", JS_EXTRACTION_FN))), ImmutableList.<String>of());
}
Also used : AndDimFilter(io.druid.query.filter.AndDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) Test(org.junit.Test)

Example 27 with AndDimFilter

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

the class GroupByQueryRunnerTest method testDimFilterHavingSpec.

@Test
public void testDimFilterHavingSpec() {
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "business", "rows", 2L, "idx", 217L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "mezzanine", "rows", 6L, "idx", 4420L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "premium", "rows", 6L, "idx", 4416L));
    final DimFilterHavingSpec havingSpec = new DimFilterHavingSpec(new AndDimFilter(ImmutableList.of(new OrDimFilter(ImmutableList.of(new BoundDimFilter("rows", "2", null, true, false, null, null, StringComparators.NUMERIC), new SelectorDimFilter("idx", "217", null))), new SelectorDimFilter("__time", String.valueOf(new DateTime("2011-04-01").getMillis()), null))));
    GroupByQuery.Builder builder = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setInterval("2011-04-02/2011-04-04").setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "alias"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).setGranularity(new PeriodGranularity(new Period("P1M"), null, null)).setHavingSpec(havingSpec);
    final GroupByQuery fullQuery = builder.build();
    TestHelper.assertExpectedObjects(expectedResults, GroupByQueryRunnerTestHelper.runQuery(factory, runner, fullQuery), "");
}
Also used : DimFilterHavingSpec(io.druid.query.groupby.having.DimFilterHavingSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) BoundDimFilter(io.druid.query.filter.BoundDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) DateTime(org.joda.time.DateTime) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) Row(io.druid.data.input.Row) Test(org.junit.Test)

Example 28 with AndDimFilter

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

the class TimeseriesQueryRunnerTest method testTimeseriesWithBoundFilter1.

@Test
public void testTimeseriesWithBoundFilter1() {
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.dayGran).filters(new AndDimFilter(Arrays.asList(new BoundDimFilter(QueryRunnerTestHelper.marketDimension, "spa", "spot", true, null, null, null, StringComparators.LEXICOGRAPHIC), new BoundDimFilter(QueryRunnerTestHelper.marketDimension, "spot", "spotify", null, true, null, null, StringComparators.LEXICOGRAPHIC), (DimFilter) new BoundDimFilter(QueryRunnerTestHelper.marketDimension, "SPOT", "spot", null, null, null, null, StringComparators.LEXICOGRAPHIC)))).intervals(QueryRunnerTestHelper.firstToThird).aggregators(Arrays.<AggregatorFactory>asList(QueryRunnerTestHelper.rowsCount, QueryRunnerTestHelper.indexLongSum, QueryRunnerTestHelper.qualityUniques)).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
    List<Result<TimeseriesResultValue>> expectedResults = Arrays.asList(new Result<>(new DateTime("2011-04-01"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("rows", 9L, "index", 1102L, "addRowsIndexConstant", 1112.0, "uniques", QueryRunnerTestHelper.UNIQUES_9))), new Result<>(new DateTime("2011-04-02"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("rows", 9L, "index", 1120L, "addRowsIndexConstant", 1130.0, "uniques", QueryRunnerTestHelper.UNIQUES_9))));
    Iterable<Result<TimeseriesResultValue>> results = Sequences.toList(runner.run(query, CONTEXT), Lists.<Result<TimeseriesResultValue>>newArrayList());
    TestHelper.assertExpectedResults(expectedResults, results);
}
Also used : BoundDimFilter(io.druid.query.filter.BoundDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) PostAggregator(io.druid.query.aggregation.PostAggregator) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) Test(org.junit.Test)

Example 29 with AndDimFilter

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

the class TimeseriesQueryRunnerTest method testTimeseriesWithMultiValueDimFilterAndOr1.

@Test
public void testTimeseriesWithMultiValueDimFilterAndOr1() {
    AndDimFilter andDimFilter = Druids.newAndDimFilterBuilder().fields(Arrays.<DimFilter>asList(Druids.newSelectorDimFilterBuilder().dimension(QueryRunnerTestHelper.marketDimension).value("spot").build(), Druids.newSelectorDimFilterBuilder().dimension(QueryRunnerTestHelper.placementishDimension).value("a").build())).build();
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.dayGran).filters(andDimFilter).intervals(QueryRunnerTestHelper.firstToThird).aggregators(QueryRunnerTestHelper.commonAggregators).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).descending(descending).build();
    AndDimFilter andDimFilter2 = Druids.newAndDimFilterBuilder().fields(Arrays.<DimFilter>asList(Druids.newSelectorDimFilterBuilder().dimension(QueryRunnerTestHelper.marketDimension).value("spot").build(), Druids.newSelectorDimFilterBuilder().dimension(QueryRunnerTestHelper.qualityDimension).value("automotive").build())).build();
    Iterable<Result<TimeseriesResultValue>> expectedResults = Sequences.toList(runner.run(Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.dayGran).filters(andDimFilter2).intervals(QueryRunnerTestHelper.firstToThird).aggregators(QueryRunnerTestHelper.commonAggregators).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).descending(descending).build(), CONTEXT), Lists.<Result<TimeseriesResultValue>>newArrayList());
    Iterable<Result<TimeseriesResultValue>> actualResults = Sequences.toList(runner.run(query, CONTEXT), Lists.<Result<TimeseriesResultValue>>newArrayList());
    TestHelper.assertExpectedResults(expectedResults, actualResults);
}
Also used : AndDimFilter(io.druid.query.filter.AndDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) RegexDimFilter(io.druid.query.filter.RegexDimFilter) NotDimFilter(io.druid.query.filter.NotDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) BoundDimFilter(io.druid.query.filter.BoundDimFilter) Result(io.druid.query.Result) Test(org.junit.Test)

Example 30 with AndDimFilter

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

the class DruidSemiJoin method getLeftRelWithFilter.

/**
   * Returns a copy of the left rel with the filter applied from the right-hand side. This is an expensive operation
   * since it actually executes the right-hand side query.
   */
private DruidRel<?> getLeftRelWithFilter() {
    // Build list of acceptable values from right side.
    final Set<List<String>> valuess = Sets.newHashSet();
    final List<DimFilter> filters = Lists.newArrayList();
    right.runQuery().accumulate(null, new Accumulator<Object, Object[]>() {

        @Override
        public Object accumulate(final Object dummyValue, final Object[] row) {
            final List<String> values = Lists.newArrayListWithCapacity(rightKeys.size());
            for (int i : rightKeys) {
                final Object value = row[i];
                final String stringValue = value != null ? String.valueOf(value) : "";
                values.add(stringValue);
                if (values.size() > maxSemiJoinRowsInMemory) {
                    throw new ResourceLimitExceededException(String.format("maxSemiJoinRowsInMemory[%,d] exceeded", maxSemiJoinRowsInMemory));
                }
            }
            if (valuess.add(values)) {
                final List<DimFilter> bounds = Lists.newArrayList();
                for (int i = 0; i < values.size(); i++) {
                    bounds.add(new BoundDimFilter(leftRowExtractions.get(i).getColumn(), values.get(i), values.get(i), false, false, null, leftRowExtractions.get(i).getExtractionFn(), getSourceRowSignature().naturalStringComparator(leftRowExtractions.get(i))));
                }
                filters.add(new AndDimFilter(bounds));
            }
            return null;
        }
    });
    valuess.clear();
    if (!filters.isEmpty()) {
        // Add a filter to the left side. Use OR of singleton Bound filters so they can be simplified later.
        final DimFilter semiJoinFilter = new OrDimFilter(filters);
        final DimFilter newFilter = left.getQueryBuilder().getFilter() == null ? semiJoinFilter : new AndDimFilter(ImmutableList.of(semiJoinFilter, left.getQueryBuilder().getFilter()));
        return left.withQueryBuilder(left.getQueryBuilder().withFilter(newFilter));
    } else {
        return null;
    }
}
Also used : BoundDimFilter(io.druid.query.filter.BoundDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) ResourceLimitExceededException(io.druid.query.ResourceLimitExceededException) OrDimFilter(io.druid.query.filter.OrDimFilter) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) OrDimFilter(io.druid.query.filter.OrDimFilter) DimFilter(io.druid.query.filter.DimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) BoundDimFilter(io.druid.query.filter.BoundDimFilter)

Aggregations

AndDimFilter (io.druid.query.filter.AndDimFilter)32 DimFilter (io.druid.query.filter.DimFilter)26 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)25 BoundDimFilter (io.druid.query.filter.BoundDimFilter)23 Test (org.junit.Test)21 NotDimFilter (io.druid.query.filter.NotDimFilter)15 OrDimFilter (io.druid.query.filter.OrDimFilter)15 InDimFilter (io.druid.query.filter.InDimFilter)13 Result (io.druid.query.Result)11 RegexDimFilter (io.druid.query.filter.RegexDimFilter)10 DateTime (org.joda.time.DateTime)9 List (java.util.List)8 ArrayList (java.util.ArrayList)6 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)4 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)4 Row (io.druid.data.input.Row)3 HashMap (java.util.HashMap)3 ImmutableList (com.google.common.collect.ImmutableList)2 PeriodGranularity (io.druid.java.util.common.granularity.PeriodGranularity)2 ExtractionDimFilter (io.druid.query.filter.ExtractionDimFilter)2