Class CachingLookupFunction
- java.lang.Object
-
- org.apache.flink.table.functions.UserDefinedFunction
-
- org.apache.flink.table.functions.TableFunction<org.apache.flink.table.data.RowData>
-
- org.apache.flink.table.functions.LookupFunction
-
- org.apache.flink.table.runtime.functions.table.lookup.CachingLookupFunction
-
- All Implemented Interfaces:
Serializable,org.apache.flink.table.functions.FunctionDefinition
@Internal public class CachingLookupFunction extends org.apache.flink.table.functions.LookupFunctionA wrapper function around user-provided lookup function with a cache layer.This function will check the cache on lookup request and return entries directly on cache hit, otherwise the function will invoke the actual lookup function, and store the entry into the cache after lookup for later use.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringLOOKUP_CACHE_METRIC_GROUP_NAME
-
Constructor Summary
Constructors Constructor Description CachingLookupFunction(org.apache.flink.table.connector.source.lookup.cache.LookupCache cache, org.apache.flink.table.functions.LookupFunction delegate)Create aCachingLookupFunction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()org.apache.flink.table.connector.source.lookup.cache.LookupCachegetCache()Collection<org.apache.flink.table.data.RowData>lookup(org.apache.flink.table.data.RowData keyRow)voidopen(org.apache.flink.table.functions.FunctionContext context)Open theCachingLookupFunction.-
Methods inherited from class org.apache.flink.table.functions.TableFunction
collect, finish, getKind, getParameterTypes, getResultType, getTypeInference, setCollector
-
Methods inherited from class org.apache.flink.table.functions.UserDefinedFunction
functionIdentifier, toString
-
-
-
-
Field Detail
-
LOOKUP_CACHE_METRIC_GROUP_NAME
public static final String LOOKUP_CACHE_METRIC_GROUP_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CachingLookupFunction
public CachingLookupFunction(org.apache.flink.table.connector.source.lookup.cache.LookupCache cache, @Nullable org.apache.flink.table.functions.LookupFunction delegate)Create aCachingLookupFunction.Please note that the cache may not be the final instance serving in this function. The actual cache instance will be retrieved from the
LookupCacheManagerduringopen(org.apache.flink.table.functions.FunctionContext).
-
-
Method Detail
-
open
public void open(org.apache.flink.table.functions.FunctionContext context) throws ExceptionOpen theCachingLookupFunction.In order to reduce the memory usage of the cache,
LookupCacheManageris used to provide a shared cache instance across subtasks of this function. Here we useUserDefinedFunction.functionIdentifier()as the id of the cache, which is generated by MD5 of serialized bytes of this function. As different subtasks of the function will generate the same MD5, this could promise that they will be served with the same cache instance.- Overrides:
openin classorg.apache.flink.table.functions.UserDefinedFunction- Throws:
Exception- See Also:
UserDefinedFunction.functionIdentifier()
-
lookup
public Collection<org.apache.flink.table.data.RowData> lookup(org.apache.flink.table.data.RowData keyRow) throws IOException
- Specified by:
lookupin classorg.apache.flink.table.functions.LookupFunction- Throws:
IOException
-
close
public void close() throws Exception- Overrides:
closein classorg.apache.flink.table.functions.UserDefinedFunction- Throws:
Exception
-
getCache
@VisibleForTesting public org.apache.flink.table.connector.source.lookup.cache.LookupCache getCache()
-
-