Class FunctionRegistryHolder

java.lang.Object
org.apache.drill.exec.expr.fn.registry.FunctionRegistryHolder
All Implemented Interfaces:
AutoCloseable

public class FunctionRegistryHolder extends Object implements AutoCloseable
Function registry holder stores function implementations by jar name, function name. Contains two maps that hold data by jars and functions respectively. Jars map contains each jar as a key and map of all its functions with collection of function signatures as value. Functions map contains function name as key and map of its signatures and function holder as value. All maps and collections used are concurrent to guarantee memory consistency effects. Such structure is chosen to achieve maximum speed while retrieving data by jar or by function name, since we expect infrequent registry changes. Holder is designed to allow concurrent reads and single writes to keep data consistent. This is achieved by ReadWriteLock implementation usage. Holder has number version which indicates remote function registry version number it is in sync with.

Structure example:

 JARS
 built-in   -> upper          -> upper(VARCHAR-REQUIRED)
            -> lower          -> lower(VARCHAR-REQUIRED)

 First.jar  -> upper          -> upper(VARCHAR-OPTIONAL)
            -> custom_upper   -> custom_upper(VARCHAR-REQUIRED)
                              -> custom_upper(VARCHAR-OPTIONAL)

 Second.jar -> lower          -> lower(VARCHAR-OPTIONAL)
            -> custom_upper   -> custom_upper(VARCHAR-REQUIRED)
                              -> custom_upper(VARCHAR-OPTIONAL)

 FUNCTIONS
 upper        -> upper(VARCHAR-REQUIRED)        -> function holder for upper(VARCHAR-REQUIRED)
              -> upper(VARCHAR-OPTIONAL)        -> function holder for upper(VARCHAR-OPTIONAL)

 lower        -> lower(VARCHAR-REQUIRED)        -> function holder for lower(VARCHAR-REQUIRED)
              -> lower(VARCHAR-OPTIONAL)        -> function holder for lower(VARCHAR-OPTIONAL)

 custom_upper -> custom_upper(VARCHAR-REQUIRED) -> function holder for custom_upper(VARCHAR-REQUIRED)
              -> custom_upper(VARCHAR-OPTIONAL) -> function holder for custom_upper(VARCHAR-OPTIONAL)

 custom_lower -> custom_lower(VARCHAR-REQUIRED) -> function holder for custom_lower(VARCHAR-REQUIRED)
              -> custom_lower(VARCHAR-OPTIONAL) -> function holder for custom_lower(VARCHAR-OPTIONAL)
 
where
  • First.jar is jar name represented by String.
  • upper is function name represented by String.
  • upper(VARCHAR-REQUIRED) is signature name represented by String which consist of function name, list of input parameters.
  • function holder for upper(VARCHAR-REQUIRED) is DrillFuncHolder initiated for each function.
    • Constructor Details

      • FunctionRegistryHolder

        public FunctionRegistryHolder()
    • Method Details

      • getVersion

        public int getVersion()
        This is read operation, so several users at a time can get this data.
        Returns:
        local function registry version number
      • addJars

        public void addJars(Map<String,List<FunctionHolder>> newJars, int version)
        Adds jars to the function registry. If jar with the same name already exists, it and its functions will be removed. Then jar will be added to jars and each function will be added using addFunctions(Map, List). Registry version is updated with passed version if all jars were added successfully. This is write operation, so one user at a time can call perform such action, others will wait till first user completes his action.
        Parameters:
        newJars - jars and list of their function holders, each contains function name, signature and holder
      • removeJar

        public void removeJar(String jarName)
        Removes jar from jars and all associated with jar functions from functions This is write operation, so one user at a time can call perform such action, others will wait till first user completes his action.
        Parameters:
        jarName - jar name to be removed
      • getAllJarNames

        public List<String> getAllJarNames()
        Retrieves list of all jars name present in jars This is read operation, so several users can get this data.
        Returns:
        list of all jar names
      • getAllJarsWithFunctionHolders

        public Map<String,List<FunctionHolder>> getAllJarsWithFunctionHolders()
        Retrieves all functions (holders) associated with all the jars This is read operation, so several users can perform this operation at the same time.
        Returns:
        list of all functions, mapped by their sources
      • getFunctionNamesByJar

        public List<String> getFunctionNamesByJar(String jarName)
        Retrieves all function names associated with the jar from jars. Returns empty list if jar is not registered. This is a read operation, so several users can perform this operation at the same time.
        Parameters:
        jarName - jar name
        Returns:
        list of functions names associated from the jar
      • getAllFunctionsWithHolders

        public org.apache.drill.shaded.guava.com.google.common.collect.ListMultimap<String,DrillFuncHolder> getAllFunctionsWithHolders(AtomicInteger version)
        Returns list of functions with list of function holders for each functions. Uses guava ListMultimap structure to return data. If no functions present, will return empty ListMultimap. If version holder is not null, updates it with current registry version number. This is a read operation, so several users can perform this operation at the same time.
        Parameters:
        version - version holder
        Returns:
        all functions which their holders
      • getAllFunctionsWithHolders

        public org.apache.drill.shaded.guava.com.google.common.collect.ListMultimap<String,DrillFuncHolder> getAllFunctionsWithHolders()
        Returns list of functions with list of function holders for each functions without version number. This is a read operation, so several users can perform this operation at the same time.
        Returns:
        all functions which their holders
      • getAllFunctionsWithSignatures

        public org.apache.drill.shaded.guava.com.google.common.collect.ListMultimap<String,String> getAllFunctionsWithSignatures()
        Returns list of functions with list of function signatures for each functions. Uses guava ListMultimap structure to return data. If no functions present, will return empty ListMultimap. This is a read operation, so several users can perform this operation at the same time.
        Returns:
        all functions which their signatures
      • getHoldersByFunctionName

        public List<DrillFuncHolder> getHoldersByFunctionName(String functionName, AtomicInteger version)
        Returns all function holders associated with function name. If function is not present, will return empty list. If version holder is not null, updates it with current registry version number. This is a read operation, so several users can perform this operation at the same time.
        Parameters:
        functionName - function name
        version - version holder
        Returns:
        list of function holders
      • getHoldersByFunctionName

        public List<DrillFuncHolder> getHoldersByFunctionName(String functionName)
        Returns all function holders associated with function name without version number. This is a read operation, so several users can perform this operation at the same time.
        Parameters:
        functionName - function name
        Returns:
        list of function holders
      • containsJar

        public boolean containsJar(String jarName)
        Checks is jar is present in jars. This is a read operation, so several users can perform this operation at the same time.
        Parameters:
        jarName - jar name
        Returns:
        true if jar exists, else false
      • functionsSize

        public int functionsSize()
        Returns quantity of functions stored in functions. This is a read operation, so several users can perform this operation at the same time.
        Returns:
        quantity of functions
      • getJarNameByFunctionSignature

        public String getJarNameByFunctionSignature(String functionName, String functionSignature)
        Looks which jar in jars contains passed function signature. First looks by function name and if found checks if such function has passed function signature. Returns jar name if found matching function signature, else null. This is a read operation, so several users can perform this operation at the same time.
        Parameters:
        functionName - function name
        functionSignature - function signature
        Returns:
        jar name
      • close

        public void close()
        Specified by:
        close in interface AutoCloseable