org.apache.hadoop.hive.ql.udf.generic
Class GenericUDF

java.lang.Object
  extended by org.apache.hadoop.hive.ql.udf.generic.GenericUDF
Direct Known Subclasses:
AbstractGenericUDFEWAHBitmapBop, GenericUDFArray, GenericUDFArrayContains, GenericUDFAssertTrue, GenericUDFBaseCompare, GenericUDFBetween, GenericUDFBridge, GenericUDFCase, GenericUDFCoalesce, GenericUDFConcatWS, GenericUDFElt, GenericUDFEvaluateNPE, GenericUDFEWAHBitmapEmpty, GenericUDFField, GenericUDFFormatNumber, GenericUDFFromUtcTimestamp, GenericUDFHash, GenericUDFIf, GenericUDFIn, GenericUDFIndex, GenericUDFInFile, GenericUDFInstr, GenericUDFLocate, GenericUDFMap, GenericUDFMapKeys, GenericUDFMapValues, GenericUDFNamedStruct, GenericUDFOPAnd, GenericUDFOPNot, GenericUDFOPNotNull, GenericUDFOPNull, GenericUDFOPOr, GenericUDFPrintf, GenericUDFReflect, GenericUDFSentences, GenericUDFSize, GenericUDFSortArray, GenericUDFSplit, GenericUDFStringToMap, GenericUDFStruct, GenericUDFTestGetJavaBoolean, GenericUDFTestGetJavaString, GenericUDFTestTranslate, GenericUDFTimestamp, GenericUDFToBinary, GenericUDFTranslate, GenericUDFUnion, GenericUDFWhen, GenericUDFXPath

public abstract class GenericUDF
extends Object

A Generic User-defined function (GenericUDF) for the use with Hive. New GenericUDF classes need to inherit from this GenericUDF class. The GenericUDF are superior to normal UDFs in the following ways: 1. It can accept arguments of complex types, and return complex types. 2. It can accept variable length of arguments. 3. It can accept an infinite number of function signature - for example, it's easy to write a GenericUDF that accepts array, array> and so on (arbitrary levels of nesting). 4. It can do short-circuit evaluations using DeferedObject.


Nested Class Summary
static class GenericUDF.DeferredJavaObject
          A basic dummy implementation of DeferredObject which just stores a Java Object reference.
static interface GenericUDF.DeferredObject
          A Defered Object allows us to do lazy-evaluation and short-circuiting.
 
Constructor Summary
GenericUDF()
          The constructor.
 
Method Summary
abstract  Object evaluate(GenericUDF.DeferredObject[] arguments)
          Evaluate the GenericUDF with the arguments.
abstract  String getDisplayString(String[] children)
          Get the String to be displayed in explain.
 String[] getRequiredFiles()
           
 String[] getRequiredJars()
          The following two functions can be overridden to automatically include additional resources required by this UDF.
abstract  ObjectInspector initialize(ObjectInspector[] arguments)
          Initialize this GenericUDF.
 ObjectInspector initializeAndFoldConstants(ObjectInspector[] arguments)
          Initialize this GenericUDF.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericUDF

public GenericUDF()
The constructor.

Method Detail

initialize

public abstract ObjectInspector initialize(ObjectInspector[] arguments)
                                    throws UDFArgumentException
Initialize this GenericUDF. This will be called once and only once per GenericUDF instance.

Parameters:
arguments - The ObjectInspector for the arguments
Returns:
The ObjectInspector for the return value
Throws:
UDFArgumentException - Thrown when arguments have wrong types, wrong length, etc.

initializeAndFoldConstants

public ObjectInspector initializeAndFoldConstants(ObjectInspector[] arguments)
                                           throws UDFArgumentException
Initialize this GenericUDF. Additionally, if the arguments are constant and the function is eligible to be folded, then the constant value returned by this UDF will be computed and stored in the ConstantObjectInspector returned. Otherwise, the function behaves exactly like initialize().

Throws:
UDFArgumentException

getRequiredJars

public String[] getRequiredJars()
The following two functions can be overridden to automatically include additional resources required by this UDF. The return types should be arrays of paths.


getRequiredFiles

public String[] getRequiredFiles()

evaluate

public abstract Object evaluate(GenericUDF.DeferredObject[] arguments)
                         throws HiveException
Evaluate the GenericUDF with the arguments.

Parameters:
arguments - The arguments as DeferedObject, use DeferedObject.get() to get the actual argument Object. The Objects can be inspected by the ObjectInspectors passed in the initialize call.
Returns:
The
Throws:
HiveException

getDisplayString

public abstract String getDisplayString(String[] children)
Get the String to be displayed in explain.



Copyright © 2011 The Apache Software Foundation