org.apache.pig.builtin
Class GenericInvoker<T>

java.lang.Object
  extended by org.apache.pig.EvalFunc<T>
      extended by org.apache.pig.builtin.GenericInvoker<T>
Type Parameters:
T -
Direct Known Subclasses:
InvokeForDouble, InvokeForFloat, InvokeForInt, InvokeForLong, InvokeForString

public abstract class GenericInvoker<T>
extends EvalFunc<T>

The generic Invoker class does all the common grunt work of setting up an invoker. Class-specific non-generic extensions of this class are needed for Pig to know what type of return to expect from exec, and to find the appropriate classes through reflection. All they have to do is implement the constructors that call into super(). Note that the no-parameter constructor is required, if seemingly nonsensical, for Pig to do its work.

The Invoker family of udfs understand the following class names (all case-independent):

  • String
  • Long
  • Float
  • Double
  • Int

    Invokers can also work with array arguments, represented in Pig as DataBags of single-tuple elements. Simply refer to string[], for example.

    This UDF allows one to dynamically invoke Java methods that return a T

    Usage of the Invoker family of UDFs (adjust as appropriate):

     -- invoking a static method
     DEFINE StringToLong InvokeForLong('java.lang.Long.valueOf', 'String')
     longs = FOREACH strings GENERATE StringToLong(some_chararray);
    
     -- invoking a method on an object
     DEFINE StringConcat InvokeForString('java.lang.String.concat', 'String String', 'false')
     concatenations = FOREACH strings GENERATE StringConcat(str1, str2); 
     
     

    The first argument to the constructor is the full path to desired method.
    The second argument is a list of classes of the method parameters.
    If the method is not static, the first element in this list is the object to invoke the method on.
    The second argument is optional (a no-argument static method is assumed if it is not supplied).
    The third argument is the keyword "static" (or "true") to signify that the method is static.
    The third argument is optional, and true by default.


    Field Summary
     
    Fields inherited from class org.apache.pig.EvalFunc
    log, pigLogger, reporter, returnType
     
    Constructor Summary
    GenericInvoker()
               
    GenericInvoker(String fullName)
               
    GenericInvoker(String fullName, String paramSpecsStr)
               
    GenericInvoker(String fullName, String paramSpecsStr, String isStatic)
               
     
    Method Summary
     T exec(Tuple input)
              This callback method must be implemented by all subclasses.
     Schema outputSchema(Schema input)
              Report the schema of the output of this UDF.
     
    Methods inherited from class org.apache.pig.EvalFunc
    finish, getArgToFuncMapping, getCacheFiles, getLogger, getPigLogger, getReporter, getReturnType, getSchemaName, isAsynchronous, progress, setPigLogger, setReporter, warn
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    GenericInvoker

    public GenericInvoker()

    GenericInvoker

    public GenericInvoker(String fullName)
                   throws ClassNotFoundException,
                          FrontendException,
                          SecurityException,
                          NoSuchMethodException
    Throws:
    ClassNotFoundException
    FrontendException
    SecurityException
    NoSuchMethodException

    GenericInvoker

    public GenericInvoker(String fullName,
                          String paramSpecsStr)
                   throws ClassNotFoundException,
                          FrontendException,
                          SecurityException,
                          NoSuchMethodException
    Throws:
    ClassNotFoundException
    FrontendException
    SecurityException
    NoSuchMethodException

    GenericInvoker

    public GenericInvoker(String fullName,
                          String paramSpecsStr,
                          String isStatic)
                   throws ClassNotFoundException,
                          FrontendException,
                          SecurityException,
                          NoSuchMethodException
    Throws:
    ClassNotFoundException
    FrontendException
    SecurityException
    NoSuchMethodException
    Method Detail

    exec

    public T exec(Tuple input)
           throws IOException
    Description copied from class: EvalFunc
    This callback method must be implemented by all subclasses. This is the method that will be invoked on every Tuple of a given dataset. Since the dataset may be divided up in a variety of ways the programmer should not make assumptions about state that is maintained between invocations of this method.

    Specified by:
    exec in class EvalFunc<T>
    Parameters:
    input - the Tuple to be processed.
    Returns:
    result, of type T.
    Throws:
    IOException

    outputSchema

    public Schema outputSchema(Schema input)
    Description copied from class: EvalFunc
    Report the schema of the output of this UDF. Pig will make use of this in error checking, optimization, and planning. The schema of input data to this UDF is provided.

    Overrides:
    outputSchema in class EvalFunc<T>
    Parameters:
    input - Schema of the input
    Returns:
    Schema of the output


    Copyright © ${year} The Apache Software Foundation