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