org.apache.pig
Class TypedOutputEvalFunc<OUT>

java.lang.Object
  extended by org.apache.pig.EvalFunc<OUT>
      extended by org.apache.pig.TypedOutputEvalFunc<OUT>
Direct Known Subclasses:
PrimitiveEvalFunc

public abstract class TypedOutputEvalFunc<OUT>
extends EvalFunc<OUT>

Base class for Pig UDFs that are functions from Tuples to generic type OUT. Handles marshalling objects, basic error checking, etc. Also infers outputSchema and provides a function to verify the input Tuple.

Extend this class and implement the
OUT exec(Tuple input)
method when writting a UDF that operates on multiple inputs from the Tuple.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.pig.EvalFunc
EvalFunc.SchemaType
 
Field Summary
protected  Class<OUT> outTypeClass
           
 
Fields inherited from class org.apache.pig.EvalFunc
log, pigLogger, reporter, returnType
 
Constructor Summary
TypedOutputEvalFunc()
           
 
Method Summary
protected  String getCounterGroup()
          Incremented counters will use this as the counter group.
 Class<OUT> getOutputTypeClass()
           
protected static
<T> List<Class<?>>
getTypeArguments(Class<T> baseClass, Class<? extends T> childClass)
          Get the actual type arguments a child class has used to extend a generic base class.
protected static void safeIncrCounter(String group, String name, Long increment)
           
protected  void verifyInput(Tuple input, int minimumSize)
           
protected static void verifyUdfInput(String klass, Tuple input, int minimumSize)
          Increment Hadoop counters for bad inputs which are either null or too small.
 
Methods inherited from class org.apache.pig.EvalFunc
exec, finish, getArgToFuncMapping, getCacheFiles, getInputSchema, getLogger, getPigLogger, getReporter, getReturnType, getSchemaName, getSchemaType, 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
 

Field Detail

outTypeClass

protected Class<OUT> outTypeClass
Constructor Detail

TypedOutputEvalFunc

public TypedOutputEvalFunc()
Method Detail

getOutputTypeClass

public Class<OUT> getOutputTypeClass()

verifyInput

protected void verifyInput(Tuple input,
                           int minimumSize)
                    throws IOException
Throws:
IOException

getCounterGroup

protected String getCounterGroup()
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.


getTypeArguments

protected static <T> List<Class<?>> getTypeArguments(Class<T> baseClass,
                                                     Class<? extends T> childClass)
Get the actual type arguments a child class has used to extend a generic base class.

Parameters:
baseClass - the base class
childClass - the child class
Returns:
a list of the raw classes for the actual type arguments.

verifyUdfInput

protected static void verifyUdfInput(String klass,
                                     Tuple input,
                                     int minimumSize)
                              throws IOException
Increment Hadoop counters for bad inputs which are either null or too small.

Parameters:
klass - the name of the calling class, for recording purposes
input - the tuple passed to the UDF.
minimumSize - the minimum size required of the tuple.
Throws:
IOException

safeIncrCounter

protected static void safeIncrCounter(String group,
                                      String name,
                                      Long increment)


Copyright © 2007-2012 The Apache Software Foundation