Class FunctionRegistryHolder
java.lang.Object
org.apache.drill.exec.expr.fn.registry.FunctionRegistryHolder
- All Implemented Interfaces:
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 First.jar is jar name represented by
upper is function name represented by
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
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
String
.String
.DrillFuncHolder
initiated for each function.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addJars
(Map<String, List<FunctionHolder>> newJars, int version) Adds jars to the function registry.void
close()
boolean
containsJar
(String jarName) Checks is jar is present injars
.int
Returns quantity of functions stored infunctions
.org.apache.drill.shaded.guava.com.google.common.collect.ListMultimap<String,
DrillFuncHolder> Returns list of functions with list of function holders for each functions without version number.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.Returns list of functions with list of function signatures for each functions.Retrieves list of all jars name present injars
This is read operation, so several users can get this data.Retrieves all functions (holders) associated with all the jars This is read operation, so several users can perform this operation at the same time.getFunctionNamesByJar
(String jarName) Retrieves all function names associated with the jar fromjars
.getHoldersByFunctionName
(String functionName) Returns all function holders associated with function name without version number.getHoldersByFunctionName
(String functionName, AtomicInteger version) Returns all function holders associated with function name.getJarNameByFunctionSignature
(String functionName, String functionSignature) Looks which jar injars
contains passed function signature.int
This is read operation, so several users at a time can get this data.void
Removes jar fromjars
and all associated with jar functions fromfunctions
This is write operation, so one user at a time can call perform such action, others will wait till first user completes his action.
-
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
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 tojars
and each function will be added usingaddFunctions(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
Removes jar fromjars
and all associated with jar functions fromfunctions
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
Retrieves list of all jars name present injars
This is read operation, so several users can get this data.- Returns:
- list of all jar names
-
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
Retrieves all function names associated with the jar fromjars
. 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 guavaListMultimap
structure to return data. If no functions present, will return emptyListMultimap
. 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 guavaListMultimap
structure to return data. If no functions present, will return emptyListMultimap
. This is a read operation, so several users can perform this operation at the same time.- Returns:
- all functions which their signatures
-
getHoldersByFunctionName
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 nameversion
- version holder- Returns:
- list of function holders
-
getHoldersByFunctionName
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
Checks is jar is present injars
. 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 infunctions
. This is a read operation, so several users can perform this operation at the same time.- Returns:
- quantity of functions
-
getJarNameByFunctionSignature
Looks which jar injars
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 namefunctionSignature
- function signature- Returns:
- jar name
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-