datafu.pig.bags
Class FirstTupleFromBag

java.lang.Object
  extended by org.apache.pig.EvalFunc<T>
      extended by datafu.pig.util.SimpleEvalFunc<org.apache.pig.data.Tuple>
          extended by datafu.pig.bags.FirstTupleFromBag

public class FirstTupleFromBag
extends SimpleEvalFunc<org.apache.pig.data.Tuple>

Returns the first tuple from a bag. Requires a second parameter that will be returned if the bag is empty. Example:

 define FirstTupleFromBag datafu.pig.bags.FirstTupleFromBag();

 -- input:
 -- ({(a,1)})
 input = LOAD 'input' AS (B: bag {T: tuple(alpha:CHARARRAY, numeric:INT)});

 output = FOREACH input GENERATE FirstTupleFromBag(B, null);

 -- output:
 -- (a,1)
 
 


Field Summary
 
Fields inherited from class org.apache.pig.EvalFunc
log, pigLogger, reporter, returnType
 
Constructor Summary
FirstTupleFromBag()
           
 
Method Summary
 org.apache.pig.data.Tuple call(org.apache.pig.data.DataBag bag, org.apache.pig.data.Tuple defaultValue)
           
 org.apache.pig.impl.logicalLayer.schema.Schema outputSchema(org.apache.pig.impl.logicalLayer.schema.Schema input)
          Override outputSchema so we can verify the input schema at pig compile time, instead of runtime
 
Methods inherited from class datafu.pig.util.SimpleEvalFunc
exec, getReturnType
 
Methods inherited from class org.apache.pig.EvalFunc
finish, getArgToFuncMapping, getCacheFiles, getInputSchema, getLogger, getPigLogger, getReporter, getSchemaName, isAsynchronous, 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

FirstTupleFromBag

public FirstTupleFromBag()
Method Detail

call

public org.apache.pig.data.Tuple call(org.apache.pig.data.DataBag bag,
                                      org.apache.pig.data.Tuple defaultValue)
                               throws java.io.IOException
Throws:
java.io.IOException

outputSchema

public org.apache.pig.impl.logicalLayer.schema.Schema outputSchema(org.apache.pig.impl.logicalLayer.schema.Schema input)
Description copied from class: SimpleEvalFunc
Override outputSchema so we can verify the input schema at pig compile time, instead of runtime

Overrides:
outputSchema in class SimpleEvalFunc<org.apache.pig.data.Tuple>
Parameters:
input - input schema
Returns:
call to super.outputSchema in case schema was defined elsewhere


Matthew Hayes, Sam Shah