Search in sources :

Example 1 with RegexFilteredDimensionSpec

use of io.druid.query.dimension.RegexFilteredDimensionSpec in project druid by druid-io.

the class CardinalityAggregatorTest method testSerde.

@Test
public void testSerde() throws Exception {
    CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory("billy", ImmutableList.<DimensionSpec>of(new DefaultDimensionSpec("b", "b"), new DefaultDimensionSpec("a", "a"), new DefaultDimensionSpec("c", "c")), true);
    ObjectMapper objectMapper = new DefaultObjectMapper();
    Assert.assertEquals(factory, objectMapper.readValue(objectMapper.writeValueAsString(factory), AggregatorFactory.class));
    String fieldNamesOnly = "{\"type\":\"cardinality\",\"name\":\"billy\",\"fields\":[\"b\",\"a\",\"c\"],\"byRow\":true}";
    Assert.assertEquals(factory, objectMapper.readValue(fieldNamesOnly, AggregatorFactory.class));
    CardinalityAggregatorFactory factory2 = new CardinalityAggregatorFactory("billy", ImmutableList.<DimensionSpec>of(new ExtractionDimensionSpec("b", "b", new RegexDimExtractionFn(".*", false, null)), new RegexFilteredDimensionSpec(new DefaultDimensionSpec("a", "a"), ".*"), new DefaultDimensionSpec("c", "c")), true);
    Assert.assertEquals(factory2, objectMapper.readValue(objectMapper.writeValueAsString(factory2), AggregatorFactory.class));
}
Also used : RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 2 with RegexFilteredDimensionSpec

use of io.druid.query.dimension.RegexFilteredDimensionSpec in project druid by druid-io.

the class GroupByQueryRunnerTest method testGroupByNumericStringsAsNumericWithDecoration.

@Test
public void testGroupByNumericStringsAsNumericWithDecoration() {
    if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
        expectedException.expect(UnsupportedOperationException.class);
        expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
    }
    // rows with `technology` have `170000` in the qualityNumericString field
    RegexFilteredDimensionSpec regexSpec = new RegexFilteredDimensionSpec(new DefaultDimensionSpec("qualityNumericString", "ql", ValueType.LONG), "170000");
    ListFilteredDimensionSpec listFilteredSpec = new ListFilteredDimensionSpec(new DefaultDimensionSpec("qualityNumericString", "qf", ValueType.FLOAT), Sets.newHashSet("170000"), 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();
    // "entertainment" rows are excluded by the decorated specs, they become empty rows
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "ql", 0L, "qf", 0.0, "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "ql", 170000L, "qf", 170000.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)

Example 3 with RegexFilteredDimensionSpec

use of io.druid.query.dimension.RegexFilteredDimensionSpec in project druid by druid-io.

the class MultiValuedDimensionTest method testGroupByWithDimFilterAndWithFilteredDimSpec.

@Test
public void testGroupByWithDimFilterAndWithFilteredDimSpec() throws Exception {
    GroupByQuery query = GroupByQuery.builder().setDataSource("xx").setQuerySegmentSpec(new LegacySegmentSpec("1970/3000")).setGranularity(Granularities.ALL).setDimensions(Lists.<DimensionSpec>newArrayList(new RegexFilteredDimensionSpec(new DefaultDimensionSpec("tags", "tags"), "t3"))).setAggregatorSpecs(Arrays.asList(new AggregatorFactory[] { new CountAggregatorFactory("count") })).setDimFilter(new SelectorDimFilter("tags", "t3", null)).build();
    Sequence<Row> result = helper.runQueryOnSegmentsObjs(ImmutableList.<Segment>of(new QueryableIndexSegment("sid1", queryableIndex), new IncrementalIndexSegment(incrementalIndex, "sid2")), query);
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("1970-01-01T00:00:00.000Z", "tags", "t3", "count", 4L));
    TestHelper.assertExpectedObjects(expectedResults, Sequences.toList(result, new ArrayList<Row>()), "");
}
Also used : QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) IncrementalIndexSegment(io.druid.segment.IncrementalIndexSegment) ArrayList(java.util.ArrayList) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) LegacySegmentSpec(io.druid.query.spec.LegacySegmentSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) GroupByQuery(io.druid.query.groupby.GroupByQuery) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) Row(io.druid.data.input.Row) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest) Test(org.junit.Test)

Example 4 with RegexFilteredDimensionSpec

use of io.druid.query.dimension.RegexFilteredDimensionSpec 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

DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)4 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)4 Test (org.junit.Test)4 Row (io.druid.data.input.Row)3 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)3 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)3 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)2 InDimFilter (io.druid.query.filter.InDimFilter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 DimensionSpec (io.druid.query.dimension.DimensionSpec)1 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)1 RegexDimExtractionFn (io.druid.query.extraction.RegexDimExtractionFn)1 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)1 GroupByQuery (io.druid.query.groupby.GroupByQuery)1 GroupByQueryRunnerTest (io.druid.query.groupby.GroupByQueryRunnerTest)1 LegacySegmentSpec (io.druid.query.spec.LegacySegmentSpec)1 IncrementalIndexSegment (io.druid.segment.IncrementalIndexSegment)1 QueryableIndexSegment (io.druid.segment.QueryableIndexSegment)1 ArrayList (java.util.ArrayList)1