Class FunctionLibrary


  • public class FunctionLibrary
    extends Object
    The function library is the primary way for the system to find out what functions are available, resolve function signatures, and invoke system and user-defined functions.
    • Constructor Detail

      • FunctionLibrary

        public FunctionLibrary​(FunctionTree systemFuncs,
                               FunctionTree... userFuncs)
        Construct the function library. This should be called only once by the FunctionLibraryManager.
    • Method Detail

      • getUserFunctions

        public FunctionTree[] getUserFunctions()
      • getSystemFunctions

        public FunctionTree getSystemFunctions()
      • getFunctionCategories

        public List<String> getFunctionCategories()
        Get all function categories, sorted in alphabetical order
        Returns:
        List of function category names, sorted in alphabetical order
      • getFunctionsInCategory

        public List<FunctionMethod> getFunctionsInCategory​(String category)
        Get all function in a category.
        Parameters:
        category - Category name
        Returns:
        List of FunctionMethods in a category
      • hasFunctionMethod

        public boolean hasFunctionMethod​(String name,
                                         int numArgs)
        Find function form based on function name and # of arguments.
        Parameters:
        name - Function name
        numArgs - Number of arguments
        Returns:
        Corresponding form or null if not found
      • findFunction

        public FunctionDescriptor findFunction​(String name,
                                               Class<?>[] types)
        Find a function descriptor given a name and the types of the arguments. This method matches based on case-insensitive function name and an exact match of the number and types of parameter arguments.
        Parameters:
        name - Name of the function to resolve
        types - Array of classes representing the types
        Returns:
        Descriptor if found, null if not found
      • findAllFunctions

        public List<FunctionDescriptor> findAllFunctions​(String name,
                                                         Class<?>[] types)
        Find a function descriptor given a name and the types of the arguments. This method matches based on case-insensitive function name and an exact match of the number and types of parameter arguments.
        Parameters:
        name - Name of the function to resolve
        types - Array of classes representing the types
        Returns:
        Descriptor if found, null if not found
      • determineNecessaryConversions

        public FunctionLibrary.ConversionResult determineNecessaryConversions​(String name,
                                                                              Class<?> returnType,
                                                                              Expression[] args,
                                                                              Class<?>[] types,
                                                                              boolean hasUnknownType)
                                                                       throws InvalidFunctionException
        Get the conversions that are needed to call the named function with arguments of the given type. In the case of an exact match, the list will contain all nulls. In other cases the list will contain one or more non-null values where the value is a conversion function that can be used to convert to the proper types for executing the function.
        Parameters:
        name - Name of function
        returnType -
        args -
        types - Existing types passed to the function
        Throws:
        InvalidFunctionException
      • isVarArgArrayParam

        public boolean isVarArgArrayParam​(FunctionMethod method,
                                          Class<?>[] types,
                                          int i,
                                          Class<?> targetType)
      • findTypedConversionFunction

        public FunctionDescriptor findTypedConversionFunction​(Class<?> sourceType,
                                                              Class<?> targetType)
        Find conversion function and set return type to proper type.
        Parameters:
        sourceType - The source type class
        targetType - The target type class
        Returns:
        A CONVERT function descriptor or null if not possible
      • copyFunctionChangeReturnType

        public FunctionDescriptor copyFunctionChangeReturnType​(FunctionDescriptor fd,
                                                               Class<?> returnType)
        Return a copy of the given FunctionDescriptor with the specified return type.
        Parameters:
        fd - FunctionDescriptor to be copied.
        returnType - The return type to apply to the copied FunctionDescriptor.
        Returns:
        The copy of FunctionDescriptor.
      • isConvert

        public static boolean isConvert​(Function function)
      • getBuiltInAggregateFunctions

        public List<FunctionMethod> getBuiltInAggregateFunctions​(boolean includeAnalytic)
        Return a list of the most general forms of built-in aggregate functions.
        count(*) - is not included
        textagg - is not included due to its non standard syntax
        Parameters:
        includeAnalytic - - true to include analytic functions that must be windowed
        Returns:
      • userFunctionExists

        public boolean userFunctionExists​(String resourceName)