Search in sources :

Example 6 with IntervalDimFilter

use of org.apache.druid.query.filter.IntervalDimFilter in project druid by druid-io.

the class PerSegmentQueryOptimizeTest method testFilteredAggregatorDontOptimizeOnNonTimeColumn.

@Test
public void testFilteredAggregatorDontOptimizeOnNonTimeColumn() {
    // Filter is not on __time, so no optimizations should be made.
    LongSumAggregatorFactory longSumAggregatorFactory = new LongSumAggregatorFactory("test", "test");
    FilteredAggregatorFactory aggregatorFactory = new FilteredAggregatorFactory(longSumAggregatorFactory, new IntervalDimFilter("not_time", 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));
    Assert.assertEquals(aggregatorFactory, excludedAgg);
    AggregatorFactory includedAgg = aggregatorFactory.optimizeForSegment(getOptimizationContext(include));
    Assert.assertEquals(aggregatorFactory, includedAgg);
    AggregatorFactory partialAgg = aggregatorFactory.optimizeForSegment(getOptimizationContext(partial));
    Assert.assertEquals(aggregatorFactory, partialAgg);
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) SuppressedAggregatorFactory(org.apache.druid.query.aggregation.SuppressedAggregatorFactory) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) IntervalDimFilter(org.apache.druid.query.filter.IntervalDimFilter) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 7 with IntervalDimFilter

use of org.apache.druid.query.filter.IntervalDimFilter in project druid by druid-io.

the class TimeFilteringTest method testIntervalFilter.

@Test
public void testIntervalFilter() {
    assertFilterMatches(new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, 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(ColumnHolder.TIME_COLUMN_NAME, 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(ColumnHolder.TIME_COLUMN_NAME, 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"));
    // increment timestamp by 2 hours
    String timeBoosterJsFn = "function(x) { return(x + 7200000) }";
    ExtractionFn exFn = new JavaScriptExtractionFn(timeBoosterJsFn, true, JavaScriptConfig.getEnabledInstance());
    assertFilterMatches(new IntervalDimFilter(ColumnHolder.TIME_COLUMN_NAME, Collections.singletonList(Intervals.of("1970-01-01T02:00:00.001Z/1970-01-01T02:00:00.005Z")), exFn), ImmutableList.of("1", "2", "3", "4"));
}
Also used : ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) TimeFormatExtractionFn(org.apache.druid.query.extraction.TimeFormatExtractionFn) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) IntervalDimFilter(org.apache.druid.query.filter.IntervalDimFilter) Test(org.junit.Test)

Aggregations

IntervalDimFilter (org.apache.druid.query.filter.IntervalDimFilter)7 Test (org.junit.Test)5 Interval (org.joda.time.Interval)4 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)3 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)3 ArrayList (java.util.ArrayList)2 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)2 SuppressedAggregatorFactory (org.apache.druid.query.aggregation.SuppressedAggregatorFactory)2 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)2 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)2 TimeFormatExtractionFn (org.apache.druid.query.extraction.TimeFormatExtractionFn)2 LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)2 List (java.util.List)1 OffheapBufferGenerator (org.apache.druid.offheap.OffheapBufferGenerator)1 NotDimFilter (org.apache.druid.query.filter.NotDimFilter)1 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)1 QuerySegmentSpec (org.apache.druid.query.spec.QuerySegmentSpec)1 TimeseriesQueryEngine (org.apache.druid.query.timeseries.TimeseriesQueryEngine)1 TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)1 TimeseriesQueryRunnerFactory (org.apache.druid.query.timeseries.TimeseriesQueryRunnerFactory)1