Search in sources :

Example 26 with BoundDimFilter

use of io.druid.query.filter.BoundDimFilter 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 27 with BoundDimFilter

use of io.druid.query.filter.BoundDimFilter 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 28 with BoundDimFilter

use of io.druid.query.filter.BoundDimFilter 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 29 with BoundDimFilter

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

Example 30 with BoundDimFilter

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

the class BoundFilterTest method testLexicographicMatchNumbers.

@Test
public void testLexicographicMatchNumbers() {
    assertFilterMatches(new BoundDimFilter("dim1", "1", "3", false, false, false, null, StringComparators.LEXICOGRAPHIC), ImmutableList.of("1", "2", "3"));
    assertFilterMatches(new BoundDimFilter("dim1", "1", "3", true, true, false, null, StringComparators.LEXICOGRAPHIC), ImmutableList.of("1", "2"));
    assertFilterMatches(new BoundDimFilter("dim1", "-1", "3", true, true, false, null, StringComparators.LEXICOGRAPHIC), ImmutableList.of("1", "2", "3", "6", "7"));
}
Also used : BoundDimFilter(io.druid.query.filter.BoundDimFilter) Test(org.junit.Test)

Aggregations

BoundDimFilter (io.druid.query.filter.BoundDimFilter)48 Test (org.junit.Test)38 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)23 InDimFilter (io.druid.query.filter.InDimFilter)17 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 ArrayList (java.util.ArrayList)12 AndDimFilter (io.druid.query.filter.AndDimFilter)11 DimFilter (io.druid.query.filter.DimFilter)10 OrDimFilter (io.druid.query.filter.OrDimFilter)9 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)8 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)6 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)6 List (java.util.List)6 Row (io.druid.data.input.Row)5 Interval (org.joda.time.Interval)5 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)4 DoubleSumAggregatorFactory (io.druid.query.aggregation.DoubleSumAggregatorFactory)4