@Internal public class CachingLookupFunction extends LookupFunction
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.
Modifier and Type | Field and Description |
---|---|
static String |
LOOKUP_CACHE_METRIC_GROUP_NAME |
Constructor and Description |
---|
CachingLookupFunction(LookupCache cache,
LookupFunction delegate)
Create a
CachingLookupFunction . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Tear-down method for user-defined function.
|
LookupCache |
getCache() |
Collection<RowData> |
lookup(RowData keyRow)
Synchronously lookup rows matching the lookup keys.
|
void |
open(FunctionContext context)
Open the
CachingLookupFunction . |
eval
collect, finish, getKind, getParameterTypes, getResultType, getTypeInference, setCollector
functionIdentifier, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getRequirements, isDeterministic
public static final String LOOKUP_CACHE_METRIC_GROUP_NAME
public CachingLookupFunction(LookupCache cache, @Nullable LookupFunction delegate)
CachingLookupFunction
.
Please note that the cache may not be the final instance serving in this function. The
actual cache instance will be retrieved from the LookupCacheManager
during open(org.apache.flink.table.functions.FunctionContext)
.
public void open(FunctionContext context) throws Exception
CachingLookupFunction
.
In order to reduce the memory usage of the cache, LookupCacheManager
is used to
provide a shared cache instance across subtasks of this function. Here we use UserDefinedFunction.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.
open
in class UserDefinedFunction
Exception
UserDefinedFunction.functionIdentifier()
public Collection<RowData> lookup(RowData keyRow) throws IOException
LookupFunction
Please note that the returning collection of RowData shouldn't be reused across invocations.
lookup
in class LookupFunction
keyRow
- - A RowData
that wraps lookup keys.IOException
public void close() throws Exception
UserDefinedFunction
close
in class UserDefinedFunction
Exception
@VisibleForTesting public LookupCache getCache()
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.