org.apache.hadoop.hive.ql.exec
Class FunctionRegistry

java.lang.Object
  extended by org.apache.hadoop.hive.ql.exec.FunctionRegistry

public final class FunctionRegistry
extends Object

FunctionRegistry.


Field Summary
static String LAG_FUNC_NAME
           
static String LAST_VALUE_FUNC_NAME
           
static String LEAD_FUNC_NAME
           
static String NOOP_MAP_TABLE_FUNCTION
           
static String NOOP_TABLE_FUNCTION
           
static String WINDOWING_TABLE_FUNCTION
           
 
Method Summary
static GenericUDF cloneGenericUDF(GenericUDF genericUDF)
          Create a copy of an existing GenericUDF.
static GenericUDTF cloneGenericUDTF(GenericUDTF genericUDTF)
          Create a copy of an existing GenericUDTF.
static PrimitiveObjectInspector.PrimitiveCategory getCommonCategory(TypeInfo a, TypeInfo b)
           
static TypeInfo getCommonClass(TypeInfo a, TypeInfo b)
          Find a common class that objects of both TypeInfo a and TypeInfo b can convert to.
static TypeInfo getCommonClassForComparison(TypeInfo a, TypeInfo b)
          Find a common class that objects of both TypeInfo a and TypeInfo b can convert to.
static TypeInfo getCommonClassForUnionAll(TypeInfo a, TypeInfo b)
          Find a common class for union-all operator
static FunctionInfo getFunctionInfo(String functionName)
           
static Set<String> getFunctionNames()
          Returns a set of registered function names.
static Set<String> getFunctionNames(String funcPatternStr)
          Returns a set of registered function names.
static Set<String> getFunctionSynonyms(String funcName)
          Returns the set of synonyms of the supplied function.
static GenericUDAFEvaluator getGenericUDAFEvaluator(String name, List<ObjectInspector> argumentOIs, boolean isDistinct, boolean isAllColumns)
          Get the GenericUDAF evaluator for the name and argumentClasses.
static GenericUDAFResolver getGenericUDAFResolver(String functionName)
           
static GenericUDF getGenericUDFForAnd()
          A shortcut to get the "and" GenericUDF.
static GenericUDF getGenericUDFForIndex()
          A shortcut to get the "index" GenericUDF.
static GenericUDAFEvaluator getGenericWindowingEvaluator(String name, List<ObjectInspector> argumentOIs, boolean isDistinct, boolean isAllColumns)
           
static Hive getHive()
           
static Method getMethodInternal(Class<?> udfClass, List<Method> mlist, boolean exact, List<TypeInfo> argumentsPassed)
          Gets the closest matching method corresponding to the argument list from a list of methods.
static
<T> Method
getMethodInternal(Class<? extends T> udfClass, String methodName, boolean exact, List<TypeInfo> argumentClasses)
          This method is shared between UDFRegistry and UDAFRegistry.
static TableFunctionResolver getNoopTableFunction()
           
static TableFunctionResolver getTableFunctionResolver(String name)
           
static TypeInfo getTypeInfoForPrimitiveCategory(PrimitiveTypeInfo a, PrimitiveTypeInfo b, PrimitiveObjectInspector.PrimitiveCategory typeCategory)
          Given 2 TypeInfo types and the PrimitiveCategory selected as the common class between the two, return a TypeInfo corresponding to the common PrimitiveCategory, and with type qualifiers (if applicable) that match the 2 TypeInfo types.
static WindowFunctionInfo getWindowFunctionInfo(String functionName)
           
static TableFunctionResolver getWindowingTableFunction()
           
static boolean implicitConvertable(PrimitiveObjectInspector.PrimitiveCategory from, PrimitiveObjectInspector.PrimitiveCategory to)
           
static boolean implicitConvertable(TypeInfo from, TypeInfo to)
          Returns whether it is possible to implicitly convert an object of Class from to Class to.
static boolean impliesOrder(String functionName)
          Both UDF and UDAF functions can imply order for analytical functions
static Object invoke(Method m, Object thisObject, Object... arguments)
           
static boolean isDeterministic(GenericUDF genericUDF)
          Returns whether a GenericUDF is deterministic or not.
static boolean isExactNumericType(PrimitiveTypeInfo typeInfo)
          Check if a type is exact (not approximate such as float and double).
static boolean isNativeFuncExpr(ExprNodeGenericFuncDesc fnExpr)
           
static boolean isNumericType(PrimitiveTypeInfo typeInfo)
          Check if the given type is numeric.
static boolean isOpAnd(ExprNodeDesc desc)
          Returns whether the exprNodeDesc is a node of "and".
static boolean isOpAndOrNot(ExprNodeDesc desc)
          Returns whether the exprNodeDesc is a node of "and", "or", "not".
static boolean isOpNot(ExprNodeDesc desc)
          Returns whether the exprNodeDesc is a node of "not".
static boolean isOpOr(ExprNodeDesc desc)
          Returns whether the exprNodeDesc is a node of "or".
static boolean isOpPositive(ExprNodeDesc desc)
          Returns whether the exprNodeDesc is a node of "positive".
static boolean isOpPreserveInputName(ExprNodeDesc desc)
          Returns whether the exprNodeDesc can recommend name for the expression
static boolean isRankingFunction(String name)
          Use this to check if function is ranking function
static boolean isStateful(GenericUDF genericUDF)
          Returns whether a GenericUDF is stateful or not.
static boolean isTableFunction(String name)
           
static int matchCost(TypeInfo argumentPassed, TypeInfo argumentAccepted, boolean exact)
          Returns -1 if passed does not match accepted.
static void registerFunctionsFromPluginJar(URL jarLocation, ClassLoader classLoader)
          Registers Hive functions from a plugin jar, using metadata from the jar's META-INF/class-info.xml.
static void registerGenericUDAF(boolean isNative, String functionName, GenericUDAFResolver genericUDAFResolver)
           
static void registerGenericUDF(boolean isNative, String functionName, Class<? extends GenericUDF> genericUDFClass)
           
static void registerGenericUDTF(boolean isNative, String functionName, Class<? extends GenericUDTF> genericUDTFClass)
           
static void registerTableFunction(String name, Class<? extends TableFunctionResolver> tFnCls)
           
static boolean registerTemporaryFunction(String functionName, Class<?> udfClass)
          Registers the appropriate kind of temporary function based on a class's type.
static void registerTemporaryGenericUDAF(String functionName, GenericUDAFResolver genericUDAFResolver)
           
static void registerTemporaryGenericUDF(String functionName, Class<? extends GenericUDF> genericUDFClass)
           
static void registerTemporaryGenericUDTF(String functionName, Class<? extends GenericUDTF> genericUDTFClass)
           
static void registerTemporaryMacro(String macroName, ExprNodeDesc body, List<String> colNames, List<TypeInfo> colTypes)
          Registers thae appropriate kind of temporary function based on a class's type.
static void registerTemporaryUDAF(String functionName, Class<? extends UDAF> udafClass)
           
static void registerTemporaryUDF(String functionName, Class<? extends UDF> UDFClass, boolean isOperator)
           
static void registerUDAF(boolean isNative, String functionName, Class<? extends UDAF> udafClass)
           
static void registerUDF(boolean isNative, String functionName, Class<? extends UDF> UDFClass, boolean isOperator)
           
static void registerUDF(boolean isNative, String functionName, Class<? extends UDF> UDFClass, boolean isOperator, String displayName)
           
static void registerUDF(String functionName, Class<? extends UDF> UDFClass, boolean isOperator, String displayName)
           
static void registerWindowFunction(String name, GenericUDAFResolver wFn)
           
static void registerWindowFunction(String name, GenericUDAFResolver wFn, boolean registerAsUDAF)
          Typically a WindowFunction is the same as a UDAF.
static void unregisterTemporaryUDF(String functionName)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEAD_FUNC_NAME

public static final String LEAD_FUNC_NAME
See Also:
Constant Field Values

LAG_FUNC_NAME

public static final String LAG_FUNC_NAME
See Also:
Constant Field Values

LAST_VALUE_FUNC_NAME

public static final String LAST_VALUE_FUNC_NAME
See Also:
Constant Field Values

WINDOWING_TABLE_FUNCTION

public static final String WINDOWING_TABLE_FUNCTION
See Also:
Constant Field Values

NOOP_TABLE_FUNCTION

public static final String NOOP_TABLE_FUNCTION
See Also:
Constant Field Values

NOOP_MAP_TABLE_FUNCTION

public static final String NOOP_MAP_TABLE_FUNCTION
See Also:
Constant Field Values
Method Detail

registerTemporaryUDF

public static void registerTemporaryUDF(String functionName,
                                        Class<? extends UDF> UDFClass,
                                        boolean isOperator)

registerUDF

public static void registerUDF(boolean isNative,
                               String functionName,
                               Class<? extends UDF> UDFClass,
                               boolean isOperator)

registerUDF

public static void registerUDF(String functionName,
                               Class<? extends UDF> UDFClass,
                               boolean isOperator,
                               String displayName)

registerUDF

public static void registerUDF(boolean isNative,
                               String functionName,
                               Class<? extends UDF> UDFClass,
                               boolean isOperator,
                               String displayName)

registerTemporaryGenericUDF

public static void registerTemporaryGenericUDF(String functionName,
                                               Class<? extends GenericUDF> genericUDFClass)

registerGenericUDF

public static void registerGenericUDF(boolean isNative,
                                      String functionName,
                                      Class<? extends GenericUDF> genericUDFClass)

registerTemporaryGenericUDTF

public static void registerTemporaryGenericUDTF(String functionName,
                                                Class<? extends GenericUDTF> genericUDTFClass)

registerGenericUDTF

public static void registerGenericUDTF(boolean isNative,
                                       String functionName,
                                       Class<? extends GenericUDTF> genericUDTFClass)

getFunctionInfo

public static FunctionInfo getFunctionInfo(String functionName)

getFunctionNames

public static Set<String> getFunctionNames()
Returns a set of registered function names. This is used for the CLI command "SHOW FUNCTIONS;"

Returns:
set of strings contains function names

getHive

public static Hive getHive()
                    throws HiveException
Throws:
HiveException

getFunctionNames

public static Set<String> getFunctionNames(String funcPatternStr)
Returns a set of registered function names. This is used for the CLI command "SHOW FUNCTIONS 'regular expression';" Returns an empty set when the regular expression is not valid.

Parameters:
funcPatternStr - regular expression of the interested function names
Returns:
set of strings contains function names

getFunctionSynonyms

public static Set<String> getFunctionSynonyms(String funcName)
Returns the set of synonyms of the supplied function.

Parameters:
funcName - the name of the function
Returns:
Set of synonyms for funcName

isNumericType

public static boolean isNumericType(PrimitiveTypeInfo typeInfo)
Check if the given type is numeric. String is considered numeric when used in numeric operators.

Parameters:
typeInfo -
Returns:

isExactNumericType

public static boolean isExactNumericType(PrimitiveTypeInfo typeInfo)
Check if a type is exact (not approximate such as float and double). String is considered as double, thus not exact.

Parameters:
typeInfo -
Returns:

getTypeInfoForPrimitiveCategory

public static TypeInfo getTypeInfoForPrimitiveCategory(PrimitiveTypeInfo a,
                                                       PrimitiveTypeInfo b,
                                                       PrimitiveObjectInspector.PrimitiveCategory typeCategory)
Given 2 TypeInfo types and the PrimitiveCategory selected as the common class between the two, return a TypeInfo corresponding to the common PrimitiveCategory, and with type qualifiers (if applicable) that match the 2 TypeInfo types. Examples: varchar(10), varchar(20), primitive category varchar => varchar(20) date, string, primitive category string => string

Parameters:
a - TypeInfo of the first type
b - TypeInfo of the second type
typeCategory - PrimitiveCategory of the designated common type between a and b
Returns:
TypeInfo represented by the primitive category, with any applicable type qualifiers.

getCommonClassForUnionAll

public static TypeInfo getCommonClassForUnionAll(TypeInfo a,
                                                 TypeInfo b)
Find a common class for union-all operator


getCommonClassForComparison

public static TypeInfo getCommonClassForComparison(TypeInfo a,
                                                   TypeInfo b)
Find a common class that objects of both TypeInfo a and TypeInfo b can convert to. This is used for comparing objects of type a and type b. When we are comparing string and double, we will always convert both of them to double and then compare.

Returns:
null if no common class could be found.

getCommonCategory

public static PrimitiveObjectInspector.PrimitiveCategory getCommonCategory(TypeInfo a,
                                                                           TypeInfo b)

getCommonClass

public static TypeInfo getCommonClass(TypeInfo a,
                                      TypeInfo b)
Find a common class that objects of both TypeInfo a and TypeInfo b can convert to. This is used for places other than comparison. The common class of string and double is string.

Returns:
null if no common class could be found.

implicitConvertable

public static boolean implicitConvertable(PrimitiveObjectInspector.PrimitiveCategory from,
                                          PrimitiveObjectInspector.PrimitiveCategory to)

implicitConvertable

public static boolean implicitConvertable(TypeInfo from,
                                          TypeInfo to)
Returns whether it is possible to implicitly convert an object of Class from to Class to.


getGenericUDAFEvaluator

public static GenericUDAFEvaluator getGenericUDAFEvaluator(String name,
                                                           List<ObjectInspector> argumentOIs,
                                                           boolean isDistinct,
                                                           boolean isAllColumns)
                                                    throws SemanticException
Get the GenericUDAF evaluator for the name and argumentClasses.

Parameters:
name - the name of the UDAF
argumentOIs -
isDistinct -
isAllColumns -
Returns:
The UDAF evaluator
Throws:
SemanticException

getGenericWindowingEvaluator

public static GenericUDAFEvaluator getGenericWindowingEvaluator(String name,
                                                                List<ObjectInspector> argumentOIs,
                                                                boolean isDistinct,
                                                                boolean isAllColumns)
                                                         throws SemanticException
Throws:
SemanticException

getMethodInternal

public static <T> Method getMethodInternal(Class<? extends T> udfClass,
                                           String methodName,
                                           boolean exact,
                                           List<TypeInfo> argumentClasses)
                                throws UDFArgumentException
This method is shared between UDFRegistry and UDAFRegistry. methodName will be "evaluate" for UDFRegistry, and "aggregate"/"evaluate"/"evaluatePartial" for UDAFRegistry.

Throws:
UDFArgumentException

registerTemporaryGenericUDAF

public static void registerTemporaryGenericUDAF(String functionName,
                                                GenericUDAFResolver genericUDAFResolver)

registerGenericUDAF

public static void registerGenericUDAF(boolean isNative,
                                       String functionName,
                                       GenericUDAFResolver genericUDAFResolver)

registerTemporaryUDAF

public static void registerTemporaryUDAF(String functionName,
                                         Class<? extends UDAF> udafClass)

registerUDAF

public static void registerUDAF(boolean isNative,
                                String functionName,
                                Class<? extends UDAF> udafClass)

unregisterTemporaryUDF

public static void unregisterTemporaryUDF(String functionName)
                                   throws HiveException
Throws:
HiveException

getGenericUDAFResolver

public static GenericUDAFResolver getGenericUDAFResolver(String functionName)

invoke

public static Object invoke(Method m,
                            Object thisObject,
                            Object... arguments)
                     throws HiveException
Throws:
HiveException

matchCost

public static int matchCost(TypeInfo argumentPassed,
                            TypeInfo argumentAccepted,
                            boolean exact)
Returns -1 if passed does not match accepted. Otherwise return the cost (usually 0 for no conversion and 1 for conversion).


getMethodInternal

public static Method getMethodInternal(Class<?> udfClass,
                                       List<Method> mlist,
                                       boolean exact,
                                       List<TypeInfo> argumentsPassed)
                                throws UDFArgumentException
Gets the closest matching method corresponding to the argument list from a list of methods.

Parameters:
mlist - The list of methods to inspect.
exact - Boolean to indicate whether this is an exact match or not.
argumentsPassed - The classes for the argument.
Returns:
The matching method.
Throws:
UDFArgumentException

getGenericUDFForIndex

public static GenericUDF getGenericUDFForIndex()
A shortcut to get the "index" GenericUDF. This is used for getting elements out of array and getting values out of map.


getGenericUDFForAnd

public static GenericUDF getGenericUDFForAnd()
A shortcut to get the "and" GenericUDF.


cloneGenericUDF

public static GenericUDF cloneGenericUDF(GenericUDF genericUDF)
Create a copy of an existing GenericUDF.


cloneGenericUDTF

public static GenericUDTF cloneGenericUDTF(GenericUDTF genericUDTF)
Create a copy of an existing GenericUDTF.


isDeterministic

public static boolean isDeterministic(GenericUDF genericUDF)
Returns whether a GenericUDF is deterministic or not.


isStateful

public static boolean isStateful(GenericUDF genericUDF)
Returns whether a GenericUDF is stateful or not.


isOpAndOrNot

public static boolean isOpAndOrNot(ExprNodeDesc desc)
Returns whether the exprNodeDesc is a node of "and", "or", "not".


isOpAnd

public static boolean isOpAnd(ExprNodeDesc desc)
Returns whether the exprNodeDesc is a node of "and".


isOpOr

public static boolean isOpOr(ExprNodeDesc desc)
Returns whether the exprNodeDesc is a node of "or".


isOpNot

public static boolean isOpNot(ExprNodeDesc desc)
Returns whether the exprNodeDesc is a node of "not".


isOpPositive

public static boolean isOpPositive(ExprNodeDesc desc)
Returns whether the exprNodeDesc is a node of "positive".


isOpPreserveInputName

public static boolean isOpPreserveInputName(ExprNodeDesc desc)
Returns whether the exprNodeDesc can recommend name for the expression


registerTemporaryFunction

public static boolean registerTemporaryFunction(String functionName,
                                                Class<?> udfClass)
Registers the appropriate kind of temporary function based on a class's type.

Parameters:
functionName - name under which to register function
udfClass - class implementing UD[A|T]F
Returns:
true if udfClass's type was recognized (so registration succeeded); false otherwise

registerTemporaryMacro

public static void registerTemporaryMacro(String macroName,
                                          ExprNodeDesc body,
                                          List<String> colNames,
                                          List<TypeInfo> colTypes)
Registers thae appropriate kind of temporary function based on a class's type.

Parameters:
macroName - name under which to register the macro
body - the expression which the macro evaluates to
colNames - the names of the arguments to the macro
colTypes - the types of the arguments to the macro

registerFunctionsFromPluginJar

public static void registerFunctionsFromPluginJar(URL jarLocation,
                                                  ClassLoader classLoader)
                                           throws Exception
Registers Hive functions from a plugin jar, using metadata from the jar's META-INF/class-info.xml.

Parameters:
jarLocation - URL for reading jar file
classLoader - classloader to use for loading function classes
Throws:
Exception

registerWindowFunction

public static void registerWindowFunction(String name,
                                          GenericUDAFResolver wFn)

registerWindowFunction

public static void registerWindowFunction(String name,
                                          GenericUDAFResolver wFn,
                                          boolean registerAsUDAF)
Typically a WindowFunction is the same as a UDAF. The only exceptions are Lead & Lag UDAFs. These are not registered as regular UDAFs because - we plan to support Lead & Lag as UDFs (usable only within argument expressions of UDAFs when windowing is involved). Since mFunctions holds both UDFs and UDAFs we cannot add both FunctionInfos to mFunctions. We choose to only register UDFs in mFunctions. The implication of this is that Lead/Lag UDAFs are only usable when windowing is involved.

Parameters:
name -
wFn -
registerAsUDAF -

getWindowFunctionInfo

public static WindowFunctionInfo getWindowFunctionInfo(String functionName)

impliesOrder

public static boolean impliesOrder(String functionName)
Both UDF and UDAF functions can imply order for analytical functions

Parameters:
name - name of function
Returns:
true if a GenericUDF or GenericUDAF exists for this name and implyOrder is true, false otherwise.

isTableFunction

public static boolean isTableFunction(String name)

getTableFunctionResolver

public static TableFunctionResolver getTableFunctionResolver(String name)

getWindowingTableFunction

public static TableFunctionResolver getWindowingTableFunction()

getNoopTableFunction

public static TableFunctionResolver getNoopTableFunction()

registerTableFunction

public static void registerTableFunction(String name,
                                         Class<? extends TableFunctionResolver> tFnCls)

isRankingFunction

public static boolean isRankingFunction(String name)
Use this to check if function is ranking function

Parameters:
name - name of a function
Returns:
true if function is a UDAF, has WindowFunctionDescription annotation and the annotations confirms a ranking function, false otherwise

isNativeFuncExpr

public static boolean isNativeFuncExpr(ExprNodeGenericFuncDesc fnExpr)
Parameters:
fnExpr - Function expression.
Returns:
True iff the fnExpr represents a hive built-in function.


Copyright © 2014 The Apache Software Foundation. All rights reserved.