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.


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 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 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 boolean implicitConvertable(TypeInfo from, TypeInfo to)
          Returns whether it is possible to implicitly convert an object of Class from to Class to.
static Object invoke(Method m, Object thisObject, Object... arguments)
           
static boolean isDeterministic(GenericUDF genericUDF)
          Returns whether a GenericUDF is deterministic or not.
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 isStateful(GenericUDF genericUDF)
          Returns whether a GenericUDF is stateful or not.
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 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 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 unregisterTemporaryUDF(String functionName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

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

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.

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(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

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".


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

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


Copyright © 2013 The Apache Software Foundation