org.apache.pig.builtin
Class FunctionWrapperEvalFunc

java.lang.Object
  extended by org.apache.pig.EvalFunc<OUT>
      extended by org.apache.pig.TypedOutputEvalFunc<OUT>
          extended by org.apache.pig.PrimitiveEvalFunc<Object,Object>
              extended by org.apache.pig.builtin.FunctionWrapperEvalFunc

public class FunctionWrapperEvalFunc
extends PrimitiveEvalFunc<Object,Object>

EvalFunc that wraps an implementation of the Function interface, which is passed as a String in the constructor. When resolving the Function class, the Pig UDF package import list is used.

The Function must have a default no-arg constructor, which will be used. For Functions that take args in the constructor, initialize the function in a subclass of this one and call super(function).

Example: DEFINE myUdf FunctionWrapperEvalFunc('MyFunction')


Field Summary
 
Fields inherited from class org.apache.pig.PrimitiveEvalFunc
inTypeClass
 
Fields inherited from class org.apache.pig.TypedOutputEvalFunc
outTypeClass
 
Fields inherited from class org.apache.pig.EvalFunc
log, pigLogger, reporter, returnType
 
Constructor Summary
protected FunctionWrapperEvalFunc(ExceptionalFunction function)
          Determines the input and output types of the Function and initializes the superclass.
protected FunctionWrapperEvalFunc(com.google.common.base.Function function)
          Determines the input and output types of the Function and initializes the superclass.
  FunctionWrapperEvalFunc(String functionClassName)
          Takes the class name of a Function, initializes it using the default constructor and passes it to FunctionWrapperEvalFunc(ExceptionalFunction function).
 
Method Summary
 Object exec(Object input)
           
protected  String getCounterGroup()
          Incremented counters will use this as the counter group.
 
Methods inherited from class org.apache.pig.PrimitiveEvalFunc
exec, getInputTypeClass
 
Methods inherited from class org.apache.pig.TypedOutputEvalFunc
getOutputTypeClass, getTypeArguments, safeIncrCounter, verifyInput, verifyUdfInput
 
Methods inherited from class org.apache.pig.EvalFunc
finish, getArgToFuncMapping, getCacheFiles, getInputSchema, getLogger, getPigLogger, getReporter, getReturnType, getSchemaName, isAsynchronous, outputSchema, progress, setInputSchema, setPigLogger, setReporter, setUDFContextSignature, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FunctionWrapperEvalFunc

public FunctionWrapperEvalFunc(String functionClassName)
                        throws ClassNotFoundException,
                               NoSuchMethodException,
                               IllegalAccessException,
                               InstantiationException,
                               IOException
Takes the class name of a Function, initializes it using the default constructor and passes it to FunctionWrapperEvalFunc(ExceptionalFunction function). Functions must implement either com.google.common.base.Function or ExceptionalFunction.

Parameters:
functionClassName - function class to initialize
Throws:
ClassNotFoundException
NoSuchMethodException
IllegalAccessException
InstantiationException
IOException

FunctionWrapperEvalFunc

protected FunctionWrapperEvalFunc(com.google.common.base.Function function)
                           throws IOException,
                                  ClassNotFoundException,
                                  NoSuchMethodException
Determines the input and output types of the Function and initializes the superclass. Subclass and call this constructor if a Function with a non-default constructor is required.

Parameters:
function - Function to be used by the UDF.
Throws:
IOException
ClassNotFoundException
NoSuchMethodException

FunctionWrapperEvalFunc

protected FunctionWrapperEvalFunc(ExceptionalFunction function)
                           throws IOException,
                                  ClassNotFoundException,
                                  NoSuchMethodException
Determines the input and output types of the Function and initializes the superclass. Subclass and call this constructor if a Function with a non-default constructor is required.

Parameters:
function - Function to be used by the UDF.
Throws:
IOException
ClassNotFoundException
NoSuchMethodException
Method Detail

exec

public Object exec(Object input)
            throws IOException
Specified by:
exec in class PrimitiveEvalFunc<Object,Object>
Throws:
IOException

getCounterGroup

protected String getCounterGroup()
Description copied from class: TypedOutputEvalFunc
Incremented counters will use this as the counter group. Typically this works fine, since the subclass name is enough to identify the UDF. In some cases though (i.e. a UDF wrapper that is a facade to a number of different transformation functions), a more specific group name is needed.

Overrides:
getCounterGroup in class TypedOutputEvalFunc<Object>


Copyright © 2007-2012 The Apache Software Foundation