Search in sources :

Example 11 with ContainsSearchQuerySpec

use of io.druid.query.search.search.ContainsSearchQuerySpec in project druid by druid-io.

the class TimeFilteringTest method testTimeFilterAsLong.

@Test
public void testTimeFilterAsLong() {
    assertFilterMatches(new SelectorDimFilter(Column.TIME_COLUMN_NAME, "0", null), ImmutableList.<String>of("0"));
    assertFilterMatches(new SelectorDimFilter(Column.TIME_COLUMN_NAME, "9000", null), ImmutableList.<String>of());
    assertFilterMatches(new BoundDimFilter(Column.TIME_COLUMN_NAME, "0", "4", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("0", "1", "2", "3", "4"));
    assertFilterMatches(new BoundDimFilter(Column.TIME_COLUMN_NAME, "0", "4", true, true, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("1", "2", "3"));
    assertFilterMatches(new InDimFilter(Column.TIME_COLUMN_NAME, Arrays.asList("2", "4", "8"), null), ImmutableList.<String>of("2", "4"));
    // cross the hashing threshold to test hashset implementation, filter on even values
    List<String> infilterValues = new ArrayList<>(InDimFilter.NUMERIC_HASHING_THRESHOLD * 2);
    for (int i = 0; i < InDimFilter.NUMERIC_HASHING_THRESHOLD * 2; i++) {
        infilterValues.add(String.valueOf(i * 2));
    }
    assertFilterMatches(new InDimFilter(Column.TIME_COLUMN_NAME, infilterValues, null), ImmutableList.<String>of("0", "2", "4"));
    String jsFn = "function(x) { return(x === 3 || x === 5) }";
    assertFilterMatches(new JavaScriptDimFilter(Column.TIME_COLUMN_NAME, jsFn, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("3", "5"));
    assertFilterMatches(new RegexDimFilter(Column.TIME_COLUMN_NAME, "4", null), ImmutableList.<String>of("4"));
    assertFilterMatches(new SearchQueryDimFilter(Column.TIME_COLUMN_NAME, new ContainsSearchQuerySpec("2", true), null), ImmutableList.<String>of("2"));
}
Also used : RegexDimFilter(io.druid.query.filter.RegexDimFilter) BoundDimFilter(io.druid.query.filter.BoundDimFilter) ContainsSearchQuerySpec(io.druid.query.search.search.ContainsSearchQuerySpec) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) ArrayList(java.util.ArrayList) SearchQueryDimFilter(io.druid.query.filter.SearchQueryDimFilter) JavaScriptDimFilter(io.druid.query.filter.JavaScriptDimFilter) Test(org.junit.Test)

Example 12 with ContainsSearchQuerySpec

use of io.druid.query.search.search.ContainsSearchQuerySpec in project druid by druid-io.

the class FloatFilteringTest method testFloatColumnFiltering.

@Test
public void testFloatColumnFiltering() {
    assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "0", null), ImmutableList.<String>of());
    assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "0.0", null), ImmutableList.<String>of());
    assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "3", null), ImmutableList.<String>of("3"));
    assertFilterMatches(new SelectorDimFilter(FLOAT_COLUMN, "3.0", null), ImmutableList.<String>of("3"));
    assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "2", "5", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "2.0", "5.0", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "1", "4", true, true, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3"));
    assertFilterMatches(new BoundDimFilter(FLOAT_COLUMN, "1.0", "4.0", true, true, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3"));
    assertFilterMatches(new InDimFilter(FLOAT_COLUMN, Arrays.asList("2", "4", "8"), null), ImmutableList.<String>of("2", "4"));
    assertFilterMatches(new InDimFilter(FLOAT_COLUMN, Arrays.asList("2.0", "4.0", "8.0"), null), ImmutableList.<String>of("2", "4"));
    // cross the hashing threshold to test hashset implementation, filter on even values
    List<String> infilterValues = new ArrayList<>(InDimFilter.NUMERIC_HASHING_THRESHOLD * 2);
    for (int i = 0; i < InDimFilter.NUMERIC_HASHING_THRESHOLD * 2; i++) {
        infilterValues.add(String.valueOf(i * 2));
    }
    assertFilterMatches(new InDimFilter(FLOAT_COLUMN, infilterValues, null), ImmutableList.<String>of("2", "4", "6"));
    String jsFn = "function(x) { return(x === 3 || x === 5) }";
    assertFilterMatches(new JavaScriptDimFilter(FLOAT_COLUMN, jsFn, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("3", "5"));
    String jsFn2 = "function(x) { return(x === 3.0 || x === 5.0) }";
    assertFilterMatches(new JavaScriptDimFilter(FLOAT_COLUMN, jsFn2, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.<String>of("3", "5"));
    assertFilterMatches(new RegexDimFilter(FLOAT_COLUMN, "4", null), ImmutableList.<String>of("4"));
    assertFilterMatches(new RegexDimFilter(FLOAT_COLUMN, "4.0", null), ImmutableList.<String>of("4"));
    assertFilterMatches(new SearchQueryDimFilter(FLOAT_COLUMN, new ContainsSearchQuerySpec("2", true), null), ImmutableList.<String>of("2"));
    assertFilterMatches(new SearchQueryDimFilter(FLOAT_COLUMN, new ContainsSearchQuerySpec("2", true), null), ImmutableList.<String>of("2"));
}
Also used : RegexDimFilter(io.druid.query.filter.RegexDimFilter) BoundDimFilter(io.druid.query.filter.BoundDimFilter) ContainsSearchQuerySpec(io.druid.query.search.search.ContainsSearchQuerySpec) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) ArrayList(java.util.ArrayList) SearchQueryDimFilter(io.druid.query.filter.SearchQueryDimFilter) JavaScriptDimFilter(io.druid.query.filter.JavaScriptDimFilter) Test(org.junit.Test)

Aggregations

BoundDimFilter (io.druid.query.filter.BoundDimFilter)12 JavaScriptDimFilter (io.druid.query.filter.JavaScriptDimFilter)12 RegexDimFilter (io.druid.query.filter.RegexDimFilter)12 SearchQueryDimFilter (io.druid.query.filter.SearchQueryDimFilter)12 ContainsSearchQuerySpec (io.druid.query.search.search.ContainsSearchQuerySpec)12 InDimFilter (io.druid.query.filter.InDimFilter)11 Test (org.junit.Test)10 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)9 ArrayList (java.util.ArrayList)7 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)5 MapLookupExtractor (io.druid.query.extraction.MapLookupExtractor)4 OrDimFilter (io.druid.query.filter.OrDimFilter)4 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)3 DimFilter (io.druid.query.filter.DimFilter)3 LookupExtractor (io.druid.query.lookup.LookupExtractor)3 HashMap (java.util.HashMap)3 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)2 ExtractionFn (io.druid.query.extraction.ExtractionFn)2 JavaScriptExtractionFn (io.druid.query.extraction.JavaScriptExtractionFn)2 AndDimFilter (io.druid.query.filter.AndDimFilter)2