Class 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:
    Serialized Form
    • 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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      org.apache.flink.table.connector.source.lookup.cache.LookupCache getCache()  
      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 interface org.apache.flink.table.functions.FunctionDefinition

        getRequirements, isDeterministic
    • Method Detail

      • 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()