Class FunctionImplementationRegistry

All Implemented Interfaces:
AutoCloseable, FunctionLookupContext

public class FunctionImplementationRegistry extends Object implements FunctionLookupContext, AutoCloseable
Registry for functions. Notably, in addition to Drill its functions (in LocalFunctionRegistry), other PluggableFunctionRegistry (e.g., HiveFunctionRegistry) is also registered in this class
  • Constructor Details

    • FunctionImplementationRegistry

      public FunctionImplementationRegistry(DrillConfig config)
    • FunctionImplementationRegistry

      public FunctionImplementationRegistry(DrillConfig config, ScanResult classpathScan)
    • FunctionImplementationRegistry

      public FunctionImplementationRegistry(DrillConfig config, ScanResult classpathScan, OptionManager optionManager)
    • FunctionImplementationRegistry

      public FunctionImplementationRegistry(DrillConfig config, ScanResult classpathScan, OptionSet optionManager)
  • Method Details

    • register

      public void register(DrillOperatorTable operatorTable)
      Register functions in given operator table.
      operatorTable - operator table
    • findDrillFunction

      public DrillFuncHolder findDrillFunction(FunctionResolver functionResolver, FunctionCall functionCall)
      First attempts to find the Drill function implementation that matches the name, arg types and return type. If exact function implementation was not found, syncs local function registry with remote function registry if needed and tries to find function implementation one more time but this time using given functionResolver.
      Specified by:
      findDrillFunction in interface FunctionLookupContext
      functionResolver - function resolver
      functionCall - function call
      best matching function holder
    • findExactMatchingDrillFunction

      public DrillFuncHolder findExactMatchingDrillFunction(String name, List<TypeProtos.MajorType> argTypes, TypeProtos.MajorType returnType)
      Finds the Drill function implementation that matches the name, arg types and return type.
      name - function name
      argTypes - input parameters types
      returnType - function return type
      exactly matching function holder
    • findNonDrillFunction

      public AbstractFuncHolder findNonDrillFunction(FunctionCall functionCall)
      Find function implementation for given functionCall in non-Drill function registries such as Hive UDF registry. Note: Order of searching is same as order of PluggableFunctionRegistry implementations found on classpath.
      Specified by:
      findNonDrillFunction in interface FunctionLookupContext
      functionCall - function call
      drill function holder
    • isFunctionComplexOutput

      public boolean isFunctionComplexOutput(String name)
    • getLocalFunctionRegistry

      public LocalFunctionRegistry getLocalFunctionRegistry()
    • getRemoteFunctionRegistry

      public RemoteFunctionRegistry getRemoteFunctionRegistry()
    • validate

      public List<String> validate(org.apache.hadoop.fs.Path path) throws IOException
      Using given local path to jar creates unique class loader for this jar. Class loader is closed to release opened connection to jar when validation is finished. Scan jar content to receive list of all scanned classes and starts validation process against local function registry. Checks if received list of validated function is not empty.
      path - local path to jar we need to validate
      list of validated function signatures
    • syncWithRemoteRegistry

      public boolean syncWithRemoteRegistry(int version)
      Purpose of this method is to synchronize remote and local function registries if needed and to inform if function registry was changed after given version.

      To make synchronization as much light-weigh as possible, first only versions of both registries are checked without any locking. If synchronization is needed, enters synchronized block to prevent others loading the same jars. The need of synchronization is checked again (double-check lock) before comparing jars. If any missing jars are found, they are downloaded to local udf area, each is wrapped into JarScan. Once jar download is finished, all missing jars are registered in one batch. In case if any errors during jars download / registration, these errors are logged.

      During registration local function registry is updated with remote function registry version it is synced with. When at least one jar of the missing jars failed to download / register, local function registry version are not updated but jars that where successfully downloaded / registered are added to local function registry.

      If synchronization between remote and local function registry was not needed, checks if given registry version matches latest sync version to inform if function registry was changed after given version.

      version - remote function registry local function registry was based on
      true if remote and local function registries were synchronized after given version
    • getAllJarsWithFunctionsHolders

      public Map<String,List<FunctionHolder>> getAllJarsWithFunctionsHolders()
      Retrieve all functions, mapped by source jars (after syncing)
      Map of source jars and their functionHolders
    • close

      public void close()
      If deleteTmpDir is set to true, deletes generated temporary directory. Otherwise cleans up localUdfDir.
      Specified by:
      close in interface AutoCloseable