Search in sources :

Example 46 with MapLookupExtractor

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

the class SearchQueryRunnerTest method testSearchWithExtractionFilter1.

@Test
public void testSearchWithExtractionFilter1() {
    final String automotiveSnowman = "automotive☃";
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, automotiveSnowman, 93));
    final LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("automotive", automotiveSnowman), false), true, null, true, true);
    SearchQuery query = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).filters(new ExtractionDimFilter(QueryRunnerTestHelper.qualityDimension, automotiveSnowman, lookupExtractionFn, null)).intervals(QueryRunnerTestHelper.fullOnInterval).dimensions(new ExtractionDimensionSpec(QueryRunnerTestHelper.qualityDimension, null, lookupExtractionFn)).query("☃").build();
    checkSearchQuery(query, expectedHits);
}
Also used : LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) SearchQuery(io.druid.query.search.search.SearchQuery) SearchHit(io.druid.query.search.search.SearchHit) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) ExtractionDimFilter(io.druid.query.filter.ExtractionDimFilter) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 47 with MapLookupExtractor

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

the class LookupExtractionFnTest method testSimpleSerDe.

@Test
public void testSimpleSerDe() throws IOException {
    if (retainMissing && !Strings.isNullOrEmpty(replaceMissing)) {
        // skip
        return;
    }
    final LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar"), false), retainMissing, replaceMissing, injective, false);
    final String str1 = OBJECT_MAPPER.writeValueAsString(lookupExtractionFn);
    final LookupExtractionFn lookupExtractionFn2 = OBJECT_MAPPER.readValue(str1, LookupExtractionFn.class);
    Assert.assertEquals(retainMissing, lookupExtractionFn2.isRetainMissingValue());
    Assert.assertEquals(replaceMissing, lookupExtractionFn2.getReplaceMissingValueWith());
    Assert.assertEquals(injective, lookupExtractionFn2.isInjective());
    Assert.assertArrayEquals(lookupExtractionFn.getCacheKey(), lookupExtractionFn2.getCacheKey());
    Assert.assertEquals(str1, OBJECT_MAPPER.writeValueAsString(lookupExtractionFn2));
}
Also used : MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) Test(org.junit.Test)

Example 48 with MapLookupExtractor

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

the class LookupExtractionFnTest method testCacheKey.

@Test
public void testCacheKey() {
    if (retainMissing && !Strings.isNullOrEmpty(replaceMissing)) {
        // skip
        return;
    }
    final Map<String, String> weirdMap = Maps.newHashMap();
    weirdMap.put("foobar", null);
    final LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar"), false), retainMissing, replaceMissing, injective, false);
    if (Strings.isNullOrEmpty(replaceMissing) || retainMissing) {
        Assert.assertFalse(Arrays.equals(lookupExtractionFn.getCacheKey(), new LookupExtractionFn(lookupExtractionFn.getLookup(), !lookupExtractionFn.isRetainMissingValue(), lookupExtractionFn.getReplaceMissingValueWith(), lookupExtractionFn.isInjective(), false).getCacheKey()));
        Assert.assertFalse(Arrays.equals(lookupExtractionFn.getCacheKey(), new LookupExtractionFn(lookupExtractionFn.getLookup(), !lookupExtractionFn.isRetainMissingValue(), lookupExtractionFn.getReplaceMissingValueWith(), !lookupExtractionFn.isInjective(), false).getCacheKey()));
    }
    Assert.assertFalse(Arrays.equals(lookupExtractionFn.getCacheKey(), new LookupExtractionFn(new MapLookupExtractor(weirdMap, false), lookupExtractionFn.isRetainMissingValue(), lookupExtractionFn.getReplaceMissingValueWith(), lookupExtractionFn.isInjective(), false).getCacheKey()));
    Assert.assertFalse(Arrays.equals(lookupExtractionFn.getCacheKey(), new LookupExtractionFn(lookupExtractionFn.getLookup(), lookupExtractionFn.isRetainMissingValue(), lookupExtractionFn.getReplaceMissingValueWith(), !lookupExtractionFn.isInjective(), false).getCacheKey()));
}
Also used : MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) 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