use of org.apache.druid.query.filter.IntervalDimFilter in project druid by druid-io.
the class FiltrationTest method testNotIntervals.
@Test
public void testNotIntervals() {
final Filtration filtration = Filtration.create(new NotDimFilter(new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, ImmutableList.of(Intervals.of("2000/2001"), Intervals.of("2002/2003")), null)), null).optimize(RowSignature.builder().add(ColumnHolder.TIME_COLUMN_NAME, ColumnType.LONG).build());
Assert.assertEquals(ImmutableList.of(Filtration.eternity()), filtration.getIntervals());
Assert.assertEquals(new NotDimFilter(new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, ImmutableList.of(Intervals.of("2000/2001"), Intervals.of("2002/2003")), null)), filtration.getDimFilter());
}
use of org.apache.druid.query.filter.IntervalDimFilter in project druid by druid-io.
the class TimeFilteringTest method testIntervalFilterOnStringDimension.
@Test
public void testIntervalFilterOnStringDimension() {
assertFilterMatches(new IntervalDimFilter("dim0", Collections.singletonList(Intervals.of("1970-01-01T00:00:00.001Z/1970-01-01T00:00:00.005Z")), null), ImmutableList.of("1", "2", "3", "4"));
assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Intervals.of("1970-01-01T00:00:00.000Z/1970-01-01T00:00:00.003Z"), Intervals.of("1970-01-01T00:00:00.004Z/1970-01-01T00:00:00.006Z")), null), ImmutableList.of("0", "1", "2", "4", "5"));
assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Intervals.of("1970-01-01T00:00:00.000Z/1970-01-01T00:00:00.001Z"), Intervals.of("1970-01-01T00:00:00.003Z/1970-01-01T00:00:00.006Z"), Intervals.of("1970-01-01T00:00:00.002Z/1970-01-01T00:00:00.005Z")), null), ImmutableList.of("0", "2", "3", "4", "5"));
assertFilterMatches(new IntervalDimFilter("dim1", Collections.singletonList(Intervals.of("1970-01-01T00:00:00.002Z/1970-01-01T00:00:00.011Z")), null), ImmutableList.of("1", "2"));
// increment timestamp by 2 hours
String timeBoosterJsFn = "function(x) { return(Number(x) + 7200000) }";
ExtractionFn exFn = new JavaScriptExtractionFn(timeBoosterJsFn, true, JavaScriptConfig.getEnabledInstance());
assertFilterMatchesSkipVectorize(new IntervalDimFilter("dim0", Collections.singletonList(Intervals.of("1970-01-01T02:00:00.001Z/1970-01-01T02:00:00.005Z")), exFn), ImmutableList.of("1", "2", "3", "4"));
}
use of org.apache.druid.query.filter.IntervalDimFilter in project druid by druid-io.
the class FilteredAggregatorFactory method optimizeForSegment.
@Override
public AggregatorFactory optimizeForSegment(PerSegmentQueryOptimizationContext optimizationContext) {
if (dimFilter instanceof IntervalDimFilter) {
IntervalDimFilter intervalDimFilter = ((IntervalDimFilter) dimFilter);
if (intervalDimFilter.getExtractionFn() != null) {
// no support for extraction functions right now
return this;
}
if (!intervalDimFilter.getDimension().equals(ColumnHolder.TIME_COLUMN_NAME)) {
// segment time boundary optimization only applies when we filter on __time
return this;
}
Interval segmentInterval = optimizationContext.getSegmentDescriptor().getInterval();
List<Interval> filterIntervals = intervalDimFilter.getIntervals();
List<Interval> excludedFilterIntervals = new ArrayList<>();
List<Interval> effectiveFilterIntervals = new ArrayList<>();
boolean segmentIsCovered = false;
for (Interval filterInterval : filterIntervals) {
Interval overlap = filterInterval.overlap(segmentInterval);
if (overlap == null) {
excludedFilterIntervals.add(filterInterval);
continue;
}
if (overlap.equals(segmentInterval)) {
segmentIsCovered = true;
break;
} else {
// clip the overlapping interval to the segment time boundaries
effectiveFilterIntervals.add(overlap);
}
}
// we can skip applying this filter, everything in the segment will match
if (segmentIsCovered) {
return delegate;
}
// we can skip this filter, nothing in the segment would match
if (excludedFilterIntervals.size() == filterIntervals.size()) {
return new SuppressedAggregatorFactory(delegate);
}
return new FilteredAggregatorFactory(delegate, new IntervalDimFilter(intervalDimFilter.getDimension(), effectiveFilterIntervals, intervalDimFilter.getExtractionFn(), intervalDimFilter.getFilterTuning()), this.name);
} else {
return this;
}
}
use of org.apache.druid.query.filter.IntervalDimFilter in project druid by druid-io.
the class TimeCompareBenchmark method setupQueries.
private void setupQueries() {
// queries for the basic schema
GeneratorSchemaInfo basicSchema = GeneratorBasicSchemas.SCHEMA_MAP.get("basic");
QuerySegmentSpec intervalSpec = new MultipleIntervalSegmentSpec(Collections.singletonList(basicSchema.getDataInterval()));
long startMillis = basicSchema.getDataInterval().getStartMillis();
long endMillis = basicSchema.getDataInterval().getEndMillis();
long half = (endMillis - startMillis) / 2;
Interval recent = Intervals.utc(half, endMillis);
Interval previous = Intervals.utc(startMillis, half);
log.info("Recent interval: " + recent);
log.info("Previous interval: " + previous);
{
// basic.topNTimeCompare
List<AggregatorFactory> queryAggs = new ArrayList<>();
queryAggs.add(new FilteredAggregatorFactory(// jsAgg1,
new LongSumAggregatorFactory("sumLongSequential", "sumLongSequential"), new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, Collections.singletonList(recent), null)));
queryAggs.add(new FilteredAggregatorFactory(new LongSumAggregatorFactory("_cmp_sumLongSequential", "sumLongSequential"), new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, Collections.singletonList(previous), null)));
TopNQueryBuilder queryBuilderA = new TopNQueryBuilder().dataSource("blah").granularity(Granularities.ALL).dimension("dimUniform").metric("sumLongSequential").intervals(intervalSpec).aggregators(queryAggs).threshold(threshold);
topNQuery = queryBuilderA.build();
topNFactory = new TopNQueryRunnerFactory(new StupidPool<>("TopNBenchmark-compute-bufferPool", new OffheapBufferGenerator("compute", 250000000), 0, Integer.MAX_VALUE), new TopNQueryQueryToolChest(new TopNQueryConfig()), QueryBenchmarkUtil.NOOP_QUERYWATCHER);
}
{
// basic.timeseriesTimeCompare
List<AggregatorFactory> queryAggs = new ArrayList<>();
queryAggs.add(new FilteredAggregatorFactory(new LongSumAggregatorFactory("sumLongSequential", "sumLongSequential"), new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, Collections.singletonList(recent), null)));
queryAggs.add(new FilteredAggregatorFactory(new LongSumAggregatorFactory("_cmp_sumLongSequential", "sumLongSequential"), new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, Collections.singletonList(previous), null)));
Druids.TimeseriesQueryBuilder timeseriesQueryBuilder = Druids.newTimeseriesQueryBuilder().dataSource("blah").granularity(Granularities.ALL).intervals(intervalSpec).aggregators(queryAggs).descending(false);
timeseriesQuery = timeseriesQueryBuilder.build();
timeseriesFactory = new TimeseriesQueryRunnerFactory(new TimeseriesQueryQueryToolChest(), new TimeseriesQueryEngine(), QueryBenchmarkUtil.NOOP_QUERYWATCHER);
}
}
use of org.apache.druid.query.filter.IntervalDimFilter in project druid by druid-io.
the class PerSegmentQueryOptimizeTest method testFilteredAggregatorOptimize.
@Test
public void testFilteredAggregatorOptimize() {
LongSumAggregatorFactory longSumAggregatorFactory = new LongSumAggregatorFactory("test", "test");
FilteredAggregatorFactory aggregatorFactory = new FilteredAggregatorFactory(longSumAggregatorFactory, new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, Collections.singletonList(Intervals.utc(1000, 2000)), null));
Interval exclude = Intervals.utc(2000, 3000);
Interval include = Intervals.utc(1500, 1600);
Interval partial = Intervals.utc(1500, 2500);
AggregatorFactory excludedAgg = aggregatorFactory.optimizeForSegment(getOptimizationContext(exclude));
AggregatorFactory expectedSuppressedAgg = new SuppressedAggregatorFactory(longSumAggregatorFactory);
Assert.assertEquals(expectedSuppressedAgg, excludedAgg);
AggregatorFactory includedAgg = aggregatorFactory.optimizeForSegment(getOptimizationContext(include));
Assert.assertEquals(longSumAggregatorFactory, includedAgg);
AggregatorFactory partialAgg = aggregatorFactory.optimizeForSegment(getOptimizationContext(partial));
AggregatorFactory expectedPartialFilteredAgg = new FilteredAggregatorFactory(longSumAggregatorFactory, new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, Collections.singletonList(Intervals.utc(1500, 2000)), null));
Assert.assertEquals(expectedPartialFilteredAgg, partialAgg);
}
Aggregations