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.LookupFunction
A 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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    CachingLookupFunction(org.apache.flink.table.connector.source.lookup.cache.LookupCache cache, org.apache.flink.table.functions.LookupFunction delegate)
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    org.apache.flink.table.connector.source.lookup.cache.LookupCache
     
    Collection<org.apache.flink.table.data.RowData>
    lookup(org.apache.flink.table.data.RowData keyRow)
     
    void
    open(org.apache.flink.table.functions.FunctionContext context)

    Methods inherited from class org.apache.flink.table.functions.LookupFunction

    eval

    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.flink.table.functions.FunctionDefinition

    getRequirements, isDeterministic, supportsConstantFolding
  • Field Details

  • Constructor Details

  • Method Details

    • open

      public void open(org.apache.flink.table.functions.FunctionContext context) throws Exception
      Open the 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.

      Overrides:
      open in class org.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:
      lookup in class org.apache.flink.table.functions.LookupFunction
      Throws:
      IOException
    • close

      public void close() throws Exception
      Overrides:
      close in class org.apache.flink.table.functions.UserDefinedFunction
      Throws:
      Exception
    • getCache

      @VisibleForTesting public org.apache.flink.table.connector.source.lookup.cache.LookupCache getCache()