Package org.teiid.query.function
Class FunctionLibrary
- java.lang.Object
-
- org.teiid.query.function.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FunctionLibrary.ConversionResult
-
Field Summary
Fields Modifier and Type Field Description static String
ARRAY_GET
static String
CAST
static String
COALESCE
static String
COMMAND_PAYLOAD
static String
CONCAT
static String
CONCAT_OPERATOR
static String
CONCAT2
static String
CONVERT
static String
DECODEINTEGER
static String
DECODESTRING
static String
ENV
static String
ENV_VAR
static String
FORMATDATE
static String
FORMATTIME
static String
FROM_UNIXTIME
static String
IFNULL
static Set<String>
INTERNAL_SCHEMAS
static String
JSONARRAY
static String
LOOKUP
static String
MVSTATUS
static String
NULLIF
static String
NVL
static String
PARSEDATE
static String
PARSETIME
static String
SESSION_ID
static String
SPACE
static String
SUBSTRING
static String
SYS_PROP
static String
TIMESTAMPADD
static String
USER
-
Constructor Summary
Constructors Constructor Description FunctionLibrary(FunctionTree systemFuncs, FunctionTree... userFuncs)
Construct the function library.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FunctionDescriptor
copyFunctionChangeReturnType(FunctionDescriptor fd, Class<?> returnType)
Return a copy of the given FunctionDescriptor with the specified return type.FunctionLibrary.ConversionResult
determineNecessaryConversions(String name, Class<?> returnType, Expression[] args, Class<?>[] types, boolean hasUnknownType)
Get the conversions that are needed to call the named function with arguments of the given type.List<FunctionDescriptor>
findAllFunctions(String name, Class<?>[] types)
Find a function descriptor given a name and the types of the arguments.FunctionDescriptor
findFunction(String name, Class<?>[] types)
Find a function descriptor given a name and the types of the arguments.FunctionDescriptor
findTypedConversionFunction(Class<?> sourceType, Class<?> targetType)
Find conversion function and set return type to proper type.List<FunctionMethod>
getBuiltInAggregateFunctions(boolean includeAnalytic)
Return a list of the most general forms of built-in aggregate functions.FunctionDescriptor[]
getConverts(FunctionMethod method, Class<?>[] types)
List<String>
getFunctionCategories()
Get all function categories, sorted in alphabetical orderList<FunctionMethod>
getFunctionsInCategory(String category)
Get all function in a category.FunctionTree
getSystemFunctions()
FunctionTree[]
getUserFunctions()
boolean
hasFunctionMethod(String name, int numArgs)
Find function form based on function name and # of arguments.static boolean
isConvert(Function function)
boolean
isVarArgArrayParam(FunctionMethod method, Class<?>[] types, int i, Class<?> targetType)
boolean
userFunctionExists(String resourceName)
-
-
-
Field Detail
-
CONVERT
public static final String CONVERT
- See Also:
- Constant Field Values
-
CAST
public static final String CAST
- See Also:
- Constant Field Values
-
LOOKUP
public static final String LOOKUP
- See Also:
- Constant Field Values
-
USER
public static final String USER
- See Also:
- Constant Field Values
-
ENV
public static final String ENV
- See Also:
- Constant Field Values
-
SYS_PROP
public static final String SYS_PROP
- See Also:
- Constant Field Values
-
ENV_VAR
public static final String ENV_VAR
- See Also:
- Constant Field Values
-
SESSION_ID
public static final String SESSION_ID
- See Also:
- Constant Field Values
-
DECODESTRING
public static final String DECODESTRING
- See Also:
- Constant Field Values
-
DECODEINTEGER
public static final String DECODEINTEGER
- See Also:
- Constant Field Values
-
COMMAND_PAYLOAD
public static final String COMMAND_PAYLOAD
- See Also:
- Constant Field Values
-
CONCAT
public static final String CONCAT
- See Also:
- Constant Field Values
-
CONCAT2
public static final String CONCAT2
- See Also:
- Constant Field Values
-
CONCAT_OPERATOR
public static final String CONCAT_OPERATOR
- See Also:
- Constant Field Values
-
SUBSTRING
public static final String SUBSTRING
- See Also:
- Constant Field Values
-
NVL
public static final String NVL
- See Also:
- Constant Field Values
-
IFNULL
public static final String IFNULL
- See Also:
- Constant Field Values
-
FROM_UNIXTIME
public static final String FROM_UNIXTIME
- See Also:
- Constant Field Values
-
TIMESTAMPADD
public static final String TIMESTAMPADD
- See Also:
- Constant Field Values
-
PARSETIME
public static final String PARSETIME
- See Also:
- Constant Field Values
-
PARSEDATE
public static final String PARSEDATE
- See Also:
- Constant Field Values
-
FORMATTIME
public static final String FORMATTIME
- See Also:
- Constant Field Values
-
FORMATDATE
public static final String FORMATDATE
- See Also:
- Constant Field Values
-
NULLIF
public static final String NULLIF
- See Also:
- Constant Field Values
-
COALESCE
public static final String COALESCE
- See Also:
- Constant Field Values
-
SPACE
public static final String SPACE
- See Also:
- Constant Field Values
-
ARRAY_GET
public static final String ARRAY_GET
- See Also:
- Constant Field Values
-
JSONARRAY
public static final String JSONARRAY
- See Also:
- Constant Field Values
-
MVSTATUS
public static final String MVSTATUS
- See Also:
- Constant Field Values
-
-
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
FunctionMethod
s in a category
-
hasFunctionMethod
public boolean hasFunctionMethod(String name, int numArgs)
Find function form based on function name and # of arguments.- Parameters:
name
- Function namenumArgs
- 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 resolvetypes
- 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 resolvetypes
- 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 functionreturnType
-args
-types
- Existing types passed to the function- Throws:
InvalidFunctionException
-
getConverts
public FunctionDescriptor[] getConverts(FunctionMethod method, Class<?>[] types)
-
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 classtargetType
- 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)
-
-