org.apache.pig
Class IteratingAccumulatorEvalFunc<T>
java.lang.Object
org.apache.pig.EvalFunc<T>
org.apache.pig.AccumulatorEvalFunc<T>
org.apache.pig.IteratingAccumulatorEvalFunc<T>
- All Implemented Interfaces:
- Accumulator<T>, TerminatingAccumulator<T>
@InterfaceAudience.Public
@InterfaceStability.Unstable
public abstract class IteratingAccumulatorEvalFunc<T>
- extends AccumulatorEvalFunc<T>
- implements TerminatingAccumulator<T>
This class provides a much more intuitive way to write Accumulator UDFs.
For example, you could express IsEmpty as follows:
public class IsEmpty extends IteratingAccumulatorEvalFunc {
public Boolean exec(Iterator iter) throws IOException {
return !iter.hashNext();
}
}
Count could be implemented as follows:
public class Count extends IteratingAccumulatorEvalFunc {
public Long exec(Iterator iter) throws IOException {
long ct = 0;
for (; iter.hasNext(); iter.next()) {
ct++;
}
return ct;
}
}
Methods inherited from class org.apache.pig.EvalFunc |
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 |
IteratingAccumulatorEvalFunc
public IteratingAccumulatorEvalFunc()
isFinished
public boolean isFinished()
- Specified by:
isFinished
in interface TerminatingAccumulator<T>
accumulate
public void accumulate(Tuple input)
throws IOException
- Description copied from interface:
Accumulator
- Pass tuples to the UDF.
- Specified by:
accumulate
in interface Accumulator<T>
- Specified by:
accumulate
in class AccumulatorEvalFunc<T>
- Parameters:
input
- A tuple containing a single field, which is a bag. The bag will contain the set
of tuples being passed to the UDF in this iteration.
- Throws:
IOException
getValue
public T getValue()
- Description copied from interface:
Accumulator
- Called when all tuples from current key have been passed to accumulate.
- Specified by:
getValue
in interface Accumulator<T>
- Specified by:
getValue
in class AccumulatorEvalFunc<T>
- Returns:
- the value for the UDF for this key.
cleanup
public void cleanup()
- Description copied from interface:
Accumulator
- Called after getValue() to prepare processing for next key.
- Specified by:
cleanup
in interface Accumulator<T>
- Specified by:
cleanup
in class AccumulatorEvalFunc<T>
exec
public abstract T exec(Iterator<Tuple> iter)
throws IOException
- Throws:
IOException
Copyright © 2007-2012 The Apache Software Foundation