Search in sources :

Example 21 with InDimFilter

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

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

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

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

the class GroupByQueryRunnerTest method testGroupByFloatColumnDescending.

@Test
public void testGroupByFloatColumnDescending() {
    if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
        expectedException.expect(UnsupportedOperationException.class);
        expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
    }
    GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("qualityFloat", "qf_alias", ValueType.FLOAT))).setDimFilter(new InDimFilter("quality", Arrays.asList("entertainment", "technology"), null)).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).addOrderByColumn(new OrderByColumnSpec("qf_alias", OrderByColumnSpec.Direction.DESCENDING, StringComparators.NUMERIC)).setGranularity(QueryRunnerTestHelper.allGran).build();
    Assert.assertNotEquals(Functions.<Sequence<Row>>identity(), query.getLimitSpec().build(query.getDimensions(), query.getAggregatorSpecs(), query.getPostAggregatorSpecs()));
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "qf_alias", 17000.0f, "rows", 2L, "idx", 175L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "qf_alias", 12000.0f, "rows", 2L, "idx", 324L));
    Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Also used : OrderByColumnSpec(io.druid.query.groupby.orderby.OrderByColumnSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) InDimFilter(io.druid.query.filter.InDimFilter) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) Row(io.druid.data.input.Row) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 25 with InDimFilter

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

the class GroupByQueryRunnerTest method testGroupByDecorationOnNumerics.

@Test
public void testGroupByDecorationOnNumerics() {
    if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
        expectedException.expect(UnsupportedOperationException.class);
        expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
    }
    RegexFilteredDimensionSpec regexSpec = new RegexFilteredDimensionSpec(new DefaultDimensionSpec("qualityLong", "ql", ValueType.LONG), "1700");
    ListFilteredDimensionSpec listFilteredSpec = new ListFilteredDimensionSpec(new DefaultDimensionSpec("qualityFloat", "qf", ValueType.FLOAT), Sets.newHashSet("17000.0"), true);
    GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setDimensions(Lists.<DimensionSpec>newArrayList(regexSpec, listFilteredSpec)).setDimFilter(new InDimFilter("quality", Arrays.asList("entertainment", "technology"), null)).setAggregatorSpecs(Arrays.<AggregatorFactory>asList(new CountAggregatorFactory("count"))).setGranularity(QueryRunnerTestHelper.allGran).build();
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "ql", 0L, "qf", 0.0, "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "ql", 1700L, "qf", 17000.0, "count", 2L));
    Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Also used : ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) InDimFilter(io.druid.query.filter.InDimFilter) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) Row(io.druid.data.input.Row) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

InDimFilter (io.druid.query.filter.InDimFilter)26 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)20 Test (org.junit.Test)20 BoundDimFilter (io.druid.query.filter.BoundDimFilter)19 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)11 DimFilter (io.druid.query.filter.DimFilter)10 ArrayList (java.util.ArrayList)10 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)8 Row (io.druid.data.input.Row)6 AndDimFilter (io.druid.query.filter.AndDimFilter)6 OrDimFilter (io.druid.query.filter.OrDimFilter)6 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)6 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)5 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)5 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)5 HashMap (java.util.HashMap)5 MapLookupExtractor (io.druid.query.extraction.MapLookupExtractor)4