|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.pig.EvalFunc<Double>
org.apache.pig.builtin.SUM
public class SUM
Generates the sum of a set of values. This class implements
Algebraic
, so if possible the execution will
performed in a distributed fashion.
SUM can operate on any numeric type. It can also operate on bytearrays, which it will cast to doubles. It expects a bag of tuples of one record each. If Pig knows from the schema that this function will be passed a bag of integers or longs, it will use a specially adapted version of SUM that uses integer arithmetic for summing the data. The return type of SUM is double for float, double, or bytearray arguments and long for int or long arguments.
SUM implements the Accumulator
interface as well.
While this will never be
the preferred method of usage it is available in case the combiner can not be
used for a given calculation.
Nested Class Summary | |
---|---|
static class |
SUM.Final
|
static class |
SUM.Initial
|
static class |
SUM.Intermediate
|
Field Summary |
---|
Fields inherited from class org.apache.pig.EvalFunc |
---|
log, pigLogger, reporter, returnType |
Constructor Summary | |
---|---|
SUM()
|
Method Summary | |
---|---|
void |
accumulate(Tuple b)
Pass tuples to the UDF. |
void |
cleanup()
Called after getValue() to prepare processing for next key. |
Double |
exec(Tuple input)
This callback method must be implemented by all subclasses. |
List<FuncSpec> |
getArgToFuncMapping()
Allow a UDF to specify type specific implementations of itself. |
String |
getFinal()
Get the final function. |
String |
getInitial()
Get the initial function. |
String |
getIntermed()
Get the intermediate function. |
Double |
getValue()
Called when all tuples from current key have been passed to accumulate. |
Schema |
outputSchema(Schema input)
Report the schema of the output of this UDF. |
protected static Double |
sum(Tuple input)
|
protected static Double |
sumDoubles(Tuple input)
|
Methods inherited from class org.apache.pig.EvalFunc |
---|
finish, 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 |
---|
public SUM()
Method Detail |
---|
public Double exec(Tuple input) throws IOException
EvalFunc
exec
in class EvalFunc<Double>
input
- the Tuple to be processed.
IOException
public String getInitial()
Algebraic
getInitial
in interface Algebraic
public String getIntermed()
Algebraic
getIntermed
in interface Algebraic
public String getFinal()
Algebraic
getFinal
in interface Algebraic
protected static Double sum(Tuple input) throws ExecException
ExecException
protected static Double sumDoubles(Tuple input) throws ExecException
ExecException
public Schema outputSchema(Schema input)
EvalFunc
outputSchema
in class EvalFunc<Double>
input
- Schema of the input
public List<FuncSpec> getArgToFuncMapping() throws FrontendException
EvalFunc
getArgToFuncMapping
in class EvalFunc<Double>
FrontendException
public void accumulate(Tuple b) throws IOException
Accumulator
accumulate
in interface Accumulator<Double>
b
- 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.
IOException
public void cleanup()
Accumulator
cleanup
in interface Accumulator<Double>
public Double getValue()
Accumulator
getValue
in interface Accumulator<Double>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |