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);
}
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));
}
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()));
}
Aggregations