datafu.pig.bags
Class Enumerate
java.lang.Object
org.apache.pig.EvalFunc<T>
org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataBag>
datafu.pig.bags.Enumerate
- All Implemented Interfaces:
- org.apache.pig.Accumulator<org.apache.pig.data.DataBag>
public class Enumerate
- extends org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataBag>
Enumerate a bag, appending to each tuple its index within the bag.
For example:
{(A),(B),(C),(D)} => {(A,0),(B,1),(C,2),(D,3)}
The first constructor parameter (optional) dictates the starting index of the counting.
This UDF implements the accumulator interface, reducing DataBag materialization costs.
Example:
define Enumerate datafu.pig.bags.Enumerate('1');
-- input:
-- ({(100),(200),(300),(400)})
input = LOAD 'input' as (B: bag{T: tuple(v2:INT)});
-- output:
-- ({(100,1),(200,2),(300,3),(400,4)})
output = FOREACH input GENERATE Enumerate(B);
Fields inherited from class org.apache.pig.EvalFunc |
log, pigLogger, reporter, returnType |
Method Summary |
void |
accumulate(org.apache.pig.data.Tuple arg0)
|
void |
cleanup()
|
org.apache.pig.data.DataBag |
getValue()
|
org.apache.pig.impl.logicalLayer.schema.Schema |
outputSchema(org.apache.pig.impl.logicalLayer.schema.Schema input)
|
Methods inherited from class org.apache.pig.AccumulatorEvalFunc |
exec |
Methods inherited from class org.apache.pig.EvalFunc |
finish, getArgToFuncMapping, getCacheFiles, getInputSchema, getLogger, getPigLogger, getReporter, getReturnType, 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 |
Enumerate
public Enumerate()
Enumerate
public Enumerate(java.lang.String start)
accumulate
public void accumulate(org.apache.pig.data.Tuple arg0)
throws java.io.IOException
- Specified by:
accumulate
in interface org.apache.pig.Accumulator<org.apache.pig.data.DataBag>
- Specified by:
accumulate
in class org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataBag>
- Throws:
java.io.IOException
cleanup
public void cleanup()
- Specified by:
cleanup
in interface org.apache.pig.Accumulator<org.apache.pig.data.DataBag>
- Specified by:
cleanup
in class org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataBag>
getValue
public org.apache.pig.data.DataBag getValue()
- Specified by:
getValue
in interface org.apache.pig.Accumulator<org.apache.pig.data.DataBag>
- Specified by:
getValue
in class org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataBag>
outputSchema
public org.apache.pig.impl.logicalLayer.schema.Schema outputSchema(org.apache.pig.impl.logicalLayer.schema.Schema input)
- Overrides:
outputSchema
in class org.apache.pig.EvalFunc<org.apache.pig.data.DataBag>
Matthew Hayes, Sam Shah