use of io.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class TimeseriesQueryRunnerTest method testTimeSeriesWithSelectionFilterLookupExtractionFn.
@Test
public void testTimeSeriesWithSelectionFilterLookupExtractionFn() {
Map<String, String> extractionMap = new HashMap<>();
extractionMap.put("spot", "upfront");
MapLookupExtractor mapLookupExtractor = new MapLookupExtractor(extractionMap, false);
LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(mapLookupExtractor, true, null, true, true);
TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.dayGran).filters(new SelectorDimFilter(QueryRunnerTestHelper.marketDimension, "upfront", lookupExtractionFn)).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", 11L, "index", 3783L, "addRowsIndexConstant", 3795.0, "uniques", QueryRunnerTestHelper.UNIQUES_9))), new Result<>(new DateTime("2011-04-02"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("rows", 11L, "index", 3313L, "addRowsIndexConstant", 3325.0, "uniques", QueryRunnerTestHelper.UNIQUES_9))));
Iterable<Result<TimeseriesResultValue>> results = Sequences.toList(runner.run(query, CONTEXT), Lists.<Result<TimeseriesResultValue>>newArrayList());
TestHelper.assertExpectedResults(expectedResults, results);
TimeseriesQueryQueryToolChest toolChest = new TimeseriesQueryQueryToolChest(QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator());
QueryRunner<Result<TimeseriesResultValue>> optimizedRunner = toolChest.postMergeQueryDecoration(toolChest.mergeResults(toolChest.preMergeQueryDecoration(runner)));
Iterable<Result<TimeseriesResultValue>> results2 = Sequences.toList(optimizedRunner.run(query, CONTEXT), Lists.<Result<TimeseriesResultValue>>newArrayList());
TestHelper.assertExpectedResults(expectedResults, results2);
}
use of io.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class ConvertBoundsToSelectors method process.
@Override
public DimFilter process(DimFilter filter) {
if (filter instanceof BoundDimFilter) {
final BoundDimFilter bound = (BoundDimFilter) filter;
final StringComparator naturalStringComparator = sourceRowSignature.naturalStringComparator(RowExtraction.of(bound.getDimension(), bound.getExtractionFn()));
if (bound.hasUpperBound() && bound.hasLowerBound() && bound.getUpper().equals(bound.getLower()) && !bound.isUpperStrict() && !bound.isLowerStrict() && bound.getOrdering().equals(naturalStringComparator)) {
return new SelectorDimFilter(bound.getDimension(), bound.getUpper(), bound.getExtractionFn());
} else {
return filter;
}
} else {
return filter;
}
}
use of io.druid.query.filter.SelectorDimFilter in project druid by druid-io.
the class ConvertSelectorsToIns method process.
@Override
public DimFilter process(DimFilter filter) {
if (filter instanceof OrDimFilter) {
// Copy children list
final List<DimFilter> children = Lists.newArrayList(((OrDimFilter) filter).getFields());
// Group filters by dimension and extractionFn.
final Map<BoundRefKey, List<SelectorDimFilter>> selectors = Maps.newHashMap();
for (DimFilter child : children) {
if (child instanceof SelectorDimFilter) {
final SelectorDimFilter selector = (SelectorDimFilter) child;
final BoundRefKey boundRefKey = BoundRefKey.from(selector, sourceRowSignature.naturalStringComparator(RowExtraction.of(selector.getDimension(), selector.getExtractionFn())));
List<SelectorDimFilter> filterList = selectors.get(boundRefKey);
if (filterList == null) {
filterList = Lists.newArrayList();
selectors.put(boundRefKey, filterList);
}
filterList.add(selector);
}
}
// Emit IN filters for each group of size > 1.
for (Map.Entry<BoundRefKey, List<SelectorDimFilter>> entry : selectors.entrySet()) {
final List<SelectorDimFilter> filterList = entry.getValue();
if (filterList.size() > 1) {
// We found a simplification. Remove the old filters and add new ones.
final List<String> values = Lists.newArrayList();
for (final SelectorDimFilter selector : filterList) {
values.add(selector.getValue());
if (!children.remove(selector)) {
throw new ISE("WTF?! Tried to remove selector but couldn't?");
}
}
children.add(new InDimFilter(entry.getKey().getDimension(), values, entry.getKey().getExtractionFn()));
}
}
if (!children.equals(((OrDimFilter) filter).getFields())) {
return children.size() == 1 ? children.get(0) : new OrDimFilter(children);
} else {
return filter;
}
} else {
return filter;
}
}
Aggregations