Package org.apache.druid.query.lookup
Class LookupExtractor
- java.lang.Object
-
- org.apache.druid.query.lookup.LookupExtractor
-
- Direct Known Subclasses:
ImmutableLookupMap.ImmutableLookupExtractor
,MapLookupExtractor
public abstract class LookupExtractor extends Object
-
-
Constructor Summary
Constructors Constructor Description LookupExtractor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract String
apply(String key)
Apply a particular lookup methodology to the input stringMap<String,String>
applyAll(Iterable<String> keys)
abstract Map<String,String>
asMap()
Returns a Map view of this lookup extractor.long
estimateHeapFootprint()
Estimated heap footprint of this object.abstract byte[]
getCacheKey()
Create a cache key for use in results cachingboolean
isOneToOne()
abstract boolean
supportsAsMap()
Returns whether this lookup extractor'sasMap()
will return a valid map.protected abstract List<String>
unapply(String value)
Reverse lookup from a given value.Iterator<String>
unapplyAll(Set<String> values)
Reverse lookup from a given set of values.
-
-
-
Method Detail
-
apply
@Nullable public abstract String apply(@Nullable String key)
Apply a particular lookup methodology to the input string- Parameters:
key
- The value to apply the lookup to.- Returns:
- The value for this key, or null when key is `null` or when key cannot have the lookup applied to it and should be treated as missing.
-
applyAll
public Map<String,String> applyAll(Iterable<String> keys)
- Parameters:
keys
- set of keys to apply lookup for each element- Returns:
- Returns
Map
whose keys are the contents ofkeys
and whose values are computed on demand using lookup functionunapply(String)
or empty map ifvalues
is `null` User can override this method if there is a better way to perform bulk lookup
-
unapply
protected abstract List<String> unapply(@Nullable String value)
Reverse lookup from a given value. Used by the default implementation ofunapplyAll(Set)
. Otherwise unused. Implementations that overrideunapplyAll(Set)
may throwUnsupportedOperationException
from this method.- Parameters:
value
- the value to apply the reverse lookup.- Returns:
- the list of keys that maps to the provided value. In SQL-compatible null handling mode, null keys are omitted.
-
unapplyAll
@Nullable public Iterator<String> unapplyAll(Set<String> values)
Reverse lookup from a given set of values.- Parameters:
values
- set of values to reverse lookup.- Returns:
- iterator of keys that map to to the provided set of values. May contain duplicate keys. Returns null if this lookup instance does not support reverse lookups. In SQL-compatible null handling mode, null keys are omitted.
-
supportsAsMap
public abstract boolean supportsAsMap()
Returns whether this lookup extractor'sasMap()
will return a valid map.
-
asMap
public abstract Map<String,String> asMap()
Returns a Map view of this lookup extractor. The map may change along with the underlying lookup data.- Throws:
UnsupportedOperationException
- ifsupportsAsMap()
returns false.
-
getCacheKey
public abstract byte[] getCacheKey()
Create a cache key for use in results caching- Returns:
- A byte array that can be used to uniquely identify if results of a prior lookup can use the cached values
-
isOneToOne
public boolean isOneToOne()
-
estimateHeapFootprint
public long estimateHeapFootprint()
Estimated heap footprint of this object. Not guaranteed to be accurate. For example, some implementations return zero even though they do use on-heap structures. However, the most common classes,MapLookupExtractor
andImmutableLookupMap
, do have reasonable implementations. This API is provided for best-effort memory management and monitoring.
-
-