Search in sources :

Example 66 with SelectorDimFilter

use of io.druid.query.filter.SelectorDimFilter 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)

Example 67 with SelectorDimFilter

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

the class FloatFilteringTest method testMultithreaded.

@Test
public void testMultithreaded() {
    assertFilterMatchesMultithreaded(new SelectorDimFilter(FLOAT_COLUMN, "3", null), ImmutableList.<String>of("3"));
    assertFilterMatchesMultithreaded(new SelectorDimFilter(FLOAT_COLUMN, "3.0", null), ImmutableList.<String>of("3"));
    assertFilterMatchesMultithreaded(new InDimFilter(FLOAT_COLUMN, Arrays.asList("2", "4", "8"), null), ImmutableList.<String>of("2", "4"));
    assertFilterMatchesMultithreaded(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));
    }
    assertFilterMatchesMultithreaded(new InDimFilter(FLOAT_COLUMN, infilterValues, null), ImmutableList.<String>of("2", "4", "6"));
    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"));
}
Also used : BoundDimFilter(io.druid.query.filter.BoundDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 68 with SelectorDimFilter

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

the class IncrementalIndexTest method testFilteredAggregators.

@Test
public void testFilteredAggregators() throws Exception {
    long timestamp = System.currentTimeMillis();
    IncrementalIndex index = closer.closeLater(indexCreator.createIndex(new AggregatorFactory[] { new CountAggregatorFactory("count"), new FilteredAggregatorFactory(new CountAggregatorFactory("count_selector_filtered"), new SelectorDimFilter("dim2", "2", null)), new FilteredAggregatorFactory(new CountAggregatorFactory("count_bound_filtered"), new BoundDimFilter("dim2", "2", "3", false, true, null, null, StringComparators.NUMERIC)), new FilteredAggregatorFactory(new CountAggregatorFactory("count_multivaldim_filtered"), new SelectorDimFilter("dim3", "b", null)), new FilteredAggregatorFactory(new CountAggregatorFactory("count_numeric_filtered"), new SelectorDimFilter("met1", "11", null)) }));
    index.add(new MapBasedInputRow(timestamp, Arrays.asList("dim1", "dim2", "dim3"), ImmutableMap.<String, Object>of("dim1", "1", "dim2", "2", "dim3", Lists.newArrayList("b", "a"), "met1", 10)));
    index.add(new MapBasedInputRow(timestamp, Arrays.asList("dim1", "dim2", "dim3"), ImmutableMap.<String, Object>of("dim1", "3", "dim2", "4", "dim3", Lists.newArrayList("c", "d"), "met1", 11)));
    Assert.assertEquals(Arrays.asList("dim1", "dim2", "dim3"), index.getDimensionNames());
    Assert.assertEquals(Arrays.asList("count", "count_selector_filtered", "count_bound_filtered", "count_multivaldim_filtered", "count_numeric_filtered"), index.getMetricNames());
    Assert.assertEquals(2, index.size());
    final Iterator<Row> rows = index.iterator();
    Row row = rows.next();
    Assert.assertEquals(timestamp, row.getTimestampFromEpoch());
    Assert.assertEquals(Arrays.asList("1"), row.getDimension("dim1"));
    Assert.assertEquals(Arrays.asList("2"), row.getDimension("dim2"));
    Assert.assertEquals(Arrays.asList("a", "b"), row.getDimension("dim3"));
    Assert.assertEquals(1L, row.getLongMetric("count"));
    Assert.assertEquals(1L, row.getLongMetric("count_selector_filtered"));
    Assert.assertEquals(1L, row.getLongMetric("count_bound_filtered"));
    Assert.assertEquals(1L, row.getLongMetric("count_multivaldim_filtered"));
    Assert.assertEquals(0L, row.getLongMetric("count_numeric_filtered"));
    row = rows.next();
    Assert.assertEquals(timestamp, row.getTimestampFromEpoch());
    Assert.assertEquals(Arrays.asList("3"), row.getDimension("dim1"));
    Assert.assertEquals(Arrays.asList("4"), row.getDimension("dim2"));
    Assert.assertEquals(Arrays.asList("c", "d"), row.getDimension("dim3"));
    Assert.assertEquals(1L, row.getLongMetric("count"));
    Assert.assertEquals(0L, row.getLongMetric("count_selector_filtered"));
    Assert.assertEquals(0L, row.getLongMetric("count_bound_filtered"));
    Assert.assertEquals(0L, row.getLongMetric("count_multivaldim_filtered"));
    Assert.assertEquals(1L, row.getLongMetric("count_numeric_filtered"));
}
Also used : FilteredAggregatorFactory(io.druid.query.aggregation.FilteredAggregatorFactory) BoundDimFilter(io.druid.query.filter.BoundDimFilter) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) OffheapIncrementalIndex(io.druid.segment.incremental.OffheapIncrementalIndex) IncrementalIndex(io.druid.segment.incremental.IncrementalIndex) OnheapIncrementalIndex(io.druid.segment.incremental.OnheapIncrementalIndex) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) Row(io.druid.data.input.Row) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) FilteredAggregatorFactory(io.druid.query.aggregation.FilteredAggregatorFactory) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) Test(org.junit.Test)

Example 69 with SelectorDimFilter

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

the class InvalidFilteringTest method testFilterTheUnfilterable.

@Test
public void testFilterTheUnfilterable() {
    // single value matching
    assertFilterMatches(new SelectorDimFilter("hyperion", "a string", null), ImmutableList.<String>of());
    assertFilterMatches(new SelectorDimFilter("hyperion", null, null), ImmutableList.<String>of("1", "2", "3", "4", "5", "6"));
    // predicate based matching
    assertFilterMatches(new InDimFilter("hyperion", Arrays.asList("hello", "world"), null), ImmutableList.<String>of());
    assertFilterMatches(new InDimFilter("hyperion", Arrays.asList("hello", "world", null), null), ImmutableList.<String>of("1", "2", "3", "4", "5", "6"));
}
Also used : SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) Test(org.junit.Test)

Example 70 with SelectorDimFilter

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

the class LongFilteringTest method testMultithreaded.

@Test
public void testMultithreaded() {
    assertFilterMatchesMultithreaded(new SelectorDimFilter(LONG_COLUMN, "3", null), ImmutableList.<String>of("3"));
    assertFilterMatchesMultithreaded(new InDimFilter(LONG_COLUMN, 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));
    }
    assertFilterMatchesMultithreaded(new InDimFilter(LONG_COLUMN, infilterValues, null), ImmutableList.<String>of("2", "4", "6"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2", "5", false, false, null, null, StringComparators.NUMERIC), ImmutableList.<String>of("2", "3", "4", "5"));
}
Also used : BoundDimFilter(io.druid.query.filter.BoundDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)93 Test (org.junit.Test)83 BoundDimFilter (io.druid.query.filter.BoundDimFilter)34 AndDimFilter (io.druid.query.filter.AndDimFilter)26 DimFilter (io.druid.query.filter.DimFilter)25 InDimFilter (io.druid.query.filter.InDimFilter)25 OrDimFilter (io.druid.query.filter.OrDimFilter)23 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)22 Row (io.druid.data.input.Row)21 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)20 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)18 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)18 JavaScriptDimFilter (io.druid.query.filter.JavaScriptDimFilter)16 RegexDimFilter (io.druid.query.filter.RegexDimFilter)16 SearchQueryDimFilter (io.druid.query.filter.SearchQueryDimFilter)16 ArrayList (java.util.ArrayList)16 Result (io.druid.query.Result)12 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)12 DateTime (org.joda.time.DateTime)12 DimensionSpec (io.druid.query.dimension.DimensionSpec)11