use of org.apache.druid.query.extraction.MapLookupExtractor in project druid by druid-io.
the class LookupExtractionFnExpectationsTest method testNullValue.
@Test
public void testNullValue() {
final LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", ""), false), false, "REPLACE", false, false);
Assert.assertEquals("REPLACE", lookupExtractionFn.apply(null));
}
use of org.apache.druid.query.extraction.MapLookupExtractor in project druid by druid-io.
the class ScanQueryRunnerTest 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);
ScanQuery query = newTestQuery().intervals(I_0112_0114).filters(new SelectorDimFilter(QueryRunnerTestHelper.MARKET_DIMENSION, "replaced", lookupExtractionFn)).columns(QueryRunnerTestHelper.QUALITY_DIMENSION, QueryRunnerTestHelper.INDEX_METRIC).build();
Iterable<ScanResultValue> results = runner.run(QueryPlus.wrap(query)).toList();
Iterable<ScanResultValue> resultsOptimize = TOOL_CHEST.postMergeQueryDecoration(TOOL_CHEST.mergeResults(TOOL_CHEST.preMergeQueryDecoration(runner))).run(QueryPlus.wrap(query)).toList();
final List<List<Map<String, Object>>> events = toEvents(new String[] { legacy ? getTimestampName() + ":TIME" : null, null, QueryRunnerTestHelper.QUALITY_DIMENSION + ":STRING", null, null, QueryRunnerTestHelper.INDEX_METRIC + ":DOUBLE" }, // 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" });
List<ScanResultValue> expectedResults = toExpected(events, legacy ? Lists.newArrayList(getTimestampName(), QueryRunnerTestHelper.QUALITY_DIMENSION, QueryRunnerTestHelper.INDEX_METRIC) : Lists.newArrayList(QueryRunnerTestHelper.QUALITY_DIMENSION, QueryRunnerTestHelper.INDEX_METRIC), 0, 3);
verify(expectedResults, results);
verify(expectedResults, resultsOptimize);
}
use of org.apache.druid.query.extraction.MapLookupExtractor in project druid by druid-io.
the class LookupExtractionFnTest method testSimpleSerDe.
@Test
public void testSimpleSerDe() throws IOException {
if (retainMissing && !NullHandling.isNullOrEquivalent(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());
if (injective == null) {
Assert.assertEquals(lookupExtractionFn2.getLookup().isOneToOne(), lookupExtractionFn2.isInjective());
} else {
Assert.assertEquals(injective, lookupExtractionFn2.isInjective());
}
Assert.assertArrayEquals(lookupExtractionFn.getCacheKey(), lookupExtractionFn2.getCacheKey());
Assert.assertEquals(str1, OBJECT_MAPPER.writeValueAsString(lookupExtractionFn2));
}
use of org.apache.druid.query.extraction.MapLookupExtractor in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByWithRebucketRename.
@Test
public void testGroupByWithRebucketRename() {
// Cannot vectorize due to extraction dimension spec.
cannotVectorize();
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");
GroupByQuery query = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new ExtractionDimensionSpec("quality", "alias", new LookupExtractionFn(new MapLookupExtractor(map, false), false, null, false, false))).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias", "automotive0", "rows", 1L, "idx", 135L), makeRow(query, "2011-04-01", "alias", "business0", "rows", 1L, "idx", 118L), makeRow(query, "2011-04-01", "alias", "entertainment0", "rows", 1L, "idx", 158L), makeRow(query, "2011-04-01", "alias", "health0", "rows", 1L, "idx", 120L), makeRow(query, "2011-04-01", "alias", "mezzanine0", "rows", 3L, "idx", 2870L), makeRow(query, "2011-04-01", "alias", "news0", "rows", 1L, "idx", 121L), makeRow(query, "2011-04-01", "alias", "premium0", "rows", 3L, "idx", 2900L), makeRow(query, "2011-04-01", "alias", "technology0", "rows", 1L, "idx", 78L), makeRow(query, "2011-04-01", "alias", "travel0", "rows", 1L, "idx", 119L), makeRow(query, "2011-04-02", "alias", "automotive0", "rows", 1L, "idx", 147L), makeRow(query, "2011-04-02", "alias", "business0", "rows", 1L, "idx", 112L), makeRow(query, "2011-04-02", "alias", "entertainment0", "rows", 1L, "idx", 166L), makeRow(query, "2011-04-02", "alias", "health0", "rows", 1L, "idx", 113L), makeRow(query, "2011-04-02", "alias", "mezzanine0", "rows", 3L, "idx", 2447L), makeRow(query, "2011-04-02", "alias", "news0", "rows", 1L, "idx", 114L), makeRow(query, "2011-04-02", "alias", "premium0", "rows", 3L, "idx", 2505L), makeRow(query, "2011-04-02", "alias", "technology0", "rows", 1L, "idx", 97L), makeRow(query, "2011-04-02", "alias", "travel0", "rows", 1L, "idx", 126L));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "rebucket-rename");
}
use of org.apache.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 = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias")).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).setDimFilter(new ExtractionDimFilter("quality", "", lookupExtractionFn, null)).build();
List<ResultRow> expectedResults;
if (NullHandling.replaceWithDefault()) {
expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias", "mezzanine", "rows", 3L, "idx", 2870L), makeRow(query, "2011-04-01", "alias", "news", "rows", 1L, "idx", 121L), makeRow(query, "2011-04-02", "alias", "mezzanine", "rows", 3L, "idx", 2447L), makeRow(query, "2011-04-02", "alias", "news", "rows", 1L, "idx", 114L));
} else {
// Only empty string should match, nulls will not match
expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias", "news", "rows", 1L, "idx", 121L), makeRow(query, "2011-04-02", "alias", "news", "rows", 1L, "idx", 114L));
}
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "dim-extraction");
}
Aggregations