Search in sources :

Example 16 with MapLookupExtractor

use of io.druid.query.extraction.MapLookupExtractor in project druid by druid-io.

the class LookupExtractionFnExpectationsTest method testMissingKeyIsReplaced.

@Test
public void testMissingKeyIsReplaced() {
    final LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar"), false), false, "REPLACE", false, false);
    Assert.assertEquals("REPLACE", lookupExtractionFn.apply(null));
}
Also used : MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) Test(org.junit.Test)

Example 17 with MapLookupExtractor

use of io.druid.query.extraction.MapLookupExtractor in project druid by druid-io.

the class LookupExtractionFnTest method testEqualsAndHash.

@Test
public void testEqualsAndHash() {
    if (retainMissing && !Strings.isNullOrEmpty(replaceMissing)) {
        // skip
        return;
    }
    final LookupExtractionFn lookupExtractionFn1 = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar"), false), retainMissing, replaceMissing, injective, false);
    final LookupExtractionFn lookupExtractionFn2 = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar"), false), retainMissing, replaceMissing, injective, false);
    final LookupExtractionFn lookupExtractionFn3 = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar2"), false), retainMissing, replaceMissing, injective, false);
    Assert.assertEquals(lookupExtractionFn1, lookupExtractionFn2);
    Assert.assertEquals(lookupExtractionFn1.hashCode(), lookupExtractionFn2.hashCode());
    Assert.assertNotEquals(lookupExtractionFn1, lookupExtractionFn3);
    Assert.assertNotEquals(lookupExtractionFn1.hashCode(), lookupExtractionFn3.hashCode());
}
Also used : MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) Test(org.junit.Test)

Example 18 with MapLookupExtractor

use of io.druid.query.extraction.MapLookupExtractor in project druid by druid-io.

the class GroupByQueryRunnerTest method testGroupByWithExtractionDimFilterCaseMappingValueIsNullOrEmpty.

@Test
public void testGroupByWithExtractionDimFilterCaseMappingValueIsNullOrEmpty() {
    Map<String, String> extractionMap = new HashMap<>();
    extractionMap.put("automotive", "automotive0");
    extractionMap.put("business", "business0");
    extractionMap.put("entertainment", "entertainment0");
    extractionMap.put("health", "health0");
    extractionMap.put("mezzanine", null);
    extractionMap.put("news", "");
    extractionMap.put("premium", "premium0");
    extractionMap.put("technology", "technology0");
    extractionMap.put("travel", "travel0");
    MapLookupExtractor mapLookupExtractor = new MapLookupExtractor(extractionMap, false);
    LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(mapLookupExtractor, false, null, true, false);
    GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "alias"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).setDimFilter(new ExtractionDimFilter("quality", "", lookupExtractionFn, null)).build();
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "mezzanine", "rows", 3L, "idx", 2870L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "news", "rows", 1L, "idx", 121L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "mezzanine", "rows", 3L, "idx", 2447L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "news", "rows", 1L, "idx", 114L));
    Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Also used : LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) HashMap(java.util.HashMap) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) Row(io.druid.data.input.Row) ExtractionDimFilter(io.druid.query.filter.ExtractionDimFilter) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 19 with MapLookupExtractor

use of io.druid.query.extraction.MapLookupExtractor in project druid by druid-io.

the class SelectQueryRunnerTest method testFullOnSelectWithDimensionSpec.

@Test
public void testFullOnSelectWithDimensionSpec() {
    Map<String, String> map = new HashMap<>();
    map.put("automotive", "automotive0");
    map.put("business", "business0");
    map.put("entertainment", "entertainment0");
    map.put("health", "health0");
    map.put("mezzanine", "mezzanine0");
    map.put("news", "news0");
    map.put("premium", "premium0");
    map.put("technology", "technology0");
    map.put("travel", "travel0");
    SelectQuery query = newTestQuery().dimensionSpecs(Arrays.<DimensionSpec>asList(new DefaultDimensionSpec(QueryRunnerTestHelper.marketDimension, "mar"), new ExtractionDimensionSpec(QueryRunnerTestHelper.qualityDimension, "qual", new LookupExtractionFn(new MapLookupExtractor(map, true), false, null, true, false)), new DefaultDimensionSpec(QueryRunnerTestHelper.placementDimension, "place"))).build();
    HashMap<String, Object> context = new HashMap<String, Object>();
    Iterable<Result<SelectResultValue>> results = Sequences.toList(runner.run(query, context), Lists.<Result<SelectResultValue>>newArrayList());
    List<Result<SelectResultValue>> expectedResultsAsc = Arrays.asList(new Result<SelectResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new SelectResultValue(ImmutableMap.of(QueryRunnerTestHelper.segmentId, 2), Sets.newHashSet("mar", "qual", "place"), Sets.newHashSet("index", "quality_uniques", "indexMin", "indexMaxPlusTen"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, 0, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("mar", "spot").put("qual", "automotive0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 100.000000F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("mar", "spot").put("qual", "business0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 100.000000F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("mar", "spot").put("qual", "entertainment0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 100.000000F).build())))));
    List<Result<SelectResultValue>> expectedResultsDsc = Arrays.asList(new Result<SelectResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new SelectResultValue(ImmutableMap.of(QueryRunnerTestHelper.segmentId, -3), Sets.newHashSet("mar", "qual", "place"), Sets.newHashSet("index", "quality_uniques", "indexMin", "indexMaxPlusTen"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, -1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-04-15T00:00:00.000Z")).put("mar", "upfront").put("qual", "premium0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 780.27197265625F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-04-15T00:00:00.000Z")).put("mar", "upfront").put("qual", "mezzanine0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 962.731201171875F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -3, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-04-15T00:00:00.000Z")).put("mar", "total_market").put("qual", "premium0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 1029.0570068359375F).build())))));
    verify(descending ? expectedResultsDsc : expectedResultsAsc, results);
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) HashMap(java.util.HashMap) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) DateTime(org.joda.time.DateTime) ImmutableMap(com.google.common.collect.ImmutableMap) Result(io.druid.query.Result) LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 20 with MapLookupExtractor

use of io.druid.query.extraction.MapLookupExtractor in project druid by druid-io.

the class SelectQueryRunnerTest method testSelectWithFilterLookupExtractionFn.

@Test
public void testSelectWithFilterLookupExtractionFn() {
    Map<String, String> extractionMap = new HashMap<>();
    extractionMap.put("total_market", "replaced");
    MapLookupExtractor mapLookupExtractor = new MapLookupExtractor(extractionMap, false);
    LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(mapLookupExtractor, false, null, true, true);
    SelectQuery query = newTestQuery().intervals(I_0112_0114).filters(new SelectorDimFilter(QueryRunnerTestHelper.marketDimension, "replaced", lookupExtractionFn)).granularity(QueryRunnerTestHelper.dayGran).dimensionSpecs(DefaultDimensionSpec.toSpec(QueryRunnerTestHelper.qualityDimension)).metrics(Lists.<String>newArrayList(QueryRunnerTestHelper.indexMetric)).build();
    Iterable<Result<SelectResultValue>> results = Sequences.toList(runner.run(query, Maps.newHashMap()), Lists.<Result<SelectResultValue>>newArrayList());
    Iterable<Result<SelectResultValue>> resultsOptimize = Sequences.toList(toolChest.postMergeQueryDecoration(toolChest.mergeResults(toolChest.preMergeQueryDecoration(runner))).run(query, Maps.<String, Object>newHashMap()), Lists.<Result<SelectResultValue>>newArrayList());
    final List<List<Map<String, Object>>> events = toEvents(new String[] { EventHolder.timestampKey + ":TIME", null, QueryRunnerTestHelper.qualityDimension + ":STRING", null, null, QueryRunnerTestHelper.indexMetric + ":FLOAT" }, // filtered values with day granularity
    new String[] { "2011-01-12T00:00:00.000Z\ttotal_market\tmezzanine\tpreferred\tmpreferred\t1000.000000", "2011-01-12T00:00:00.000Z\ttotal_market\tpremium\tpreferred\tppreferred\t1000.000000" }, new String[] { "2011-01-13T00:00:00.000Z\ttotal_market\tmezzanine\tpreferred\tmpreferred\t1040.945505", "2011-01-13T00:00:00.000Z\ttotal_market\tpremium\tpreferred\tppreferred\t1689.012875" });
    PagingOffset offset = query.getPagingOffset(QueryRunnerTestHelper.segmentId);
    List<Result<SelectResultValue>> expectedResults = toExpected(events, Lists.newArrayList(QueryRunnerTestHelper.qualityDimension), Lists.<String>newArrayList(QueryRunnerTestHelper.indexMetric), offset.startOffset(), offset.threshold());
    verify(expectedResults, results);
    verify(expectedResults, resultsOptimize);
}
Also used : HashMap(java.util.HashMap) Result(io.druid.query.Result) LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) List(java.util.List) Test(org.junit.Test)

Aggregations

MapLookupExtractor (io.druid.query.extraction.MapLookupExtractor)48 Test (org.junit.Test)46 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)38 HashMap (java.util.HashMap)24 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)19 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)16 Result (io.druid.query.Result)15 Row (io.druid.data.input.Row)14 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)14 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)14 DateTime (org.joda.time.DateTime)14 ExtractionDimFilter (io.druid.query.filter.ExtractionDimFilter)13 PostAggregator (io.druid.query.aggregation.PostAggregator)8 HyperUniqueFinalizingPostAggregator (io.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator)7 DimensionSpec (io.druid.query.dimension.DimensionSpec)7 InDimFilter (io.druid.query.filter.InDimFilter)7 LookupExtractor (io.druid.query.lookup.LookupExtractor)7 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)6 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)6 BoundDimFilter (io.druid.query.filter.BoundDimFilter)6