Search in sources :

Example 41 with LookupExtractionFn

use of org.apache.druid.query.lookup.LookupExtractionFn in project druid by druid-io.

the class InDimFilter method optimizeLookup.

private InDimFilter optimizeLookup() {
    if (extractionFn instanceof LookupExtractionFn && ((LookupExtractionFn) extractionFn).isOptimize()) {
        LookupExtractionFn exFn = (LookupExtractionFn) extractionFn;
        LookupExtractor lookup = exFn.getLookup();
        final Set<String> keys = new HashSet<>();
        for (String value : values) {
            // We cannot do an unapply()-based optimization if the selector value
            // and the replaceMissingValuesWith value are the same, since we have to match on
            // all values that are not present in the lookup.
            final String convertedValue = NullHandling.emptyToNullIfNeeded(value);
            if (!exFn.isRetainMissingValue() && Objects.equals(convertedValue, exFn.getReplaceMissingValueWith())) {
                return this;
            }
            keys.addAll(lookup.unapply(convertedValue));
            // If the selector value is overwritten in the lookup map, don't add selector value to keys.
            if (exFn.isRetainMissingValue() && NullHandling.isNullOrEquivalent(lookup.apply(convertedValue))) {
                keys.add(convertedValue);
            }
        }
        if (keys.isEmpty()) {
            return this;
        } else {
            return new InDimFilter(dimension, keys, null, filterTuning);
        }
    }
    return this;
}
Also used : LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) LookupExtractor(org.apache.druid.query.lookup.LookupExtractor) HashSet(java.util.HashSet) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet)

Aggregations

LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)41 MapLookupExtractor (org.apache.druid.query.extraction.MapLookupExtractor)40 Test (org.junit.Test)39 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)30 HashMap (java.util.HashMap)23 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)20 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)18 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)14 Result (org.apache.druid.query.Result)13 ExtractionDimFilter (org.apache.druid.query.filter.ExtractionDimFilter)13 LookupExtractor (org.apache.druid.query.lookup.LookupExtractor)9 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)8 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)8 InDimFilter (org.apache.druid.query.filter.InDimFilter)7 JavaScriptDimFilter (org.apache.druid.query.filter.JavaScriptDimFilter)6 RegexDimFilter (org.apache.druid.query.filter.RegexDimFilter)6 SearchQueryDimFilter (org.apache.druid.query.filter.SearchQueryDimFilter)6 ArrayList (java.util.ArrayList)5 AndDimFilter (org.apache.druid.query.filter.AndDimFilter)5 DimFilter (org.apache.druid.query.filter.DimFilter)5