Search in sources :

Example 1 with IntervalDimFilter

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

the class TimeFilteringTest method testIntervalFilterOnStringDimension.

@Test
public void testIntervalFilterOnStringDimension() {
    assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Interval.parse("1970-01-01T00:00:00.001Z/1970-01-01T00:00:00.005Z")), null), ImmutableList.<String>of("1", "2", "3", "4"));
    assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Interval.parse("1970-01-01T00:00:00.000Z/1970-01-01T00:00:00.003Z"), Interval.parse("1970-01-01T00:00:00.004Z/1970-01-01T00:00:00.006Z")), null), ImmutableList.<String>of("0", "1", "2", "4", "5"));
    assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Interval.parse("1970-01-01T00:00:00.000Z/1970-01-01T00:00:00.001Z"), Interval.parse("1970-01-01T00:00:00.003Z/1970-01-01T00:00:00.006Z"), Interval.parse("1970-01-01T00:00:00.002Z/1970-01-01T00:00:00.005Z")), null), ImmutableList.<String>of("0", "2", "3", "4", "5"));
    assertFilterMatches(new IntervalDimFilter("dim1", Arrays.asList(Interval.parse("1970-01-01T00:00:00.002Z/1970-01-01T00:00:00.011Z")), null), ImmutableList.<String>of("1", "2"));
    // increment timestamp by 2 hours
    String timeBoosterJsFn = "function(x) { return(Number(x) + 7200000) }";
    ExtractionFn exFn = new JavaScriptExtractionFn(timeBoosterJsFn, true, JavaScriptConfig.getEnabledInstance());
    assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Interval.parse("1970-01-01T02:00:00.001Z/1970-01-01T02:00:00.005Z")), exFn), ImmutableList.<String>of("1", "2", "3", "4"));
}
Also used : LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) ExtractionFn(io.druid.query.extraction.ExtractionFn) TimeFormatExtractionFn(io.druid.query.extraction.TimeFormatExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) IntervalDimFilter(io.druid.query.filter.IntervalDimFilter) Test(org.junit.Test)

Example 2 with IntervalDimFilter

use of io.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(Column.TIME_COLUMN_NAME, ImmutableList.of(new Interval("2000/2001"), new Interval("2002/2003")), null)), null).optimize(null);
    Assert.assertEquals(ImmutableList.of(Filtration.eternity()), filtration.getIntervals());
    Assert.assertEquals(new NotDimFilter(new IntervalDimFilter(Column.TIME_COLUMN_NAME, ImmutableList.of(new Interval("2000/2001"), new Interval("2002/2003")), null)), filtration.getDimFilter());
}
Also used : NotDimFilter(io.druid.query.filter.NotDimFilter) IntervalDimFilter(io.druid.query.filter.IntervalDimFilter) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 3 with IntervalDimFilter

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

the class TimeFilteringTest method testIntervalFilter.

@Test
public void testIntervalFilter() {
    assertFilterMatches(new IntervalDimFilter(Column.TIME_COLUMN_NAME, Arrays.asList(Interval.parse("1970-01-01T00:00:00.001Z/1970-01-01T00:00:00.005Z")), null), ImmutableList.<String>of("1", "2", "3", "4"));
    assertFilterMatches(new IntervalDimFilter(Column.TIME_COLUMN_NAME, Arrays.asList(Interval.parse("1970-01-01T00:00:00.000Z/1970-01-01T00:00:00.003Z"), Interval.parse("1970-01-01T00:00:00.004Z/1970-01-01T00:00:00.006Z")), null), ImmutableList.<String>of("0", "1", "2", "4", "5"));
    assertFilterMatches(new IntervalDimFilter(Column.TIME_COLUMN_NAME, Arrays.asList(Interval.parse("1970-01-01T00:00:00.000Z/1970-01-01T00:00:00.001Z"), Interval.parse("1970-01-01T00:00:00.003Z/1970-01-01T00:00:00.006Z"), Interval.parse("1970-01-01T00:00:00.002Z/1970-01-01T00:00:00.005Z")), null), ImmutableList.<String>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(Column.TIME_COLUMN_NAME, Arrays.asList(Interval.parse("1970-01-01T02:00:00.001Z/1970-01-01T02:00:00.005Z")), exFn), ImmutableList.<String>of("1", "2", "3", "4"));
}
Also used : LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) ExtractionFn(io.druid.query.extraction.ExtractionFn) TimeFormatExtractionFn(io.druid.query.extraction.TimeFormatExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) IntervalDimFilter(io.druid.query.filter.IntervalDimFilter) Test(org.junit.Test)

Aggregations

IntervalDimFilter (io.druid.query.filter.IntervalDimFilter)3 Test (org.junit.Test)3 ExtractionFn (io.druid.query.extraction.ExtractionFn)2 JavaScriptExtractionFn (io.druid.query.extraction.JavaScriptExtractionFn)2 TimeFormatExtractionFn (io.druid.query.extraction.TimeFormatExtractionFn)2 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)2 NotDimFilter (io.druid.query.filter.NotDimFilter)1 Interval (org.joda.time.Interval)1