org.apache.pig.builtin
Class SUM
java.lang.Object
org.apache.pig.EvalFunc<T>
org.apache.pig.builtin.AlgebraicByteArrayMathBase
org.apache.pig.builtin.SUM
- All Implemented Interfaces:
- Accumulator<Double>, Algebraic
public class SUM
- extends AlgebraicByteArrayMathBase
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.
Constructor Summary |
SUM()
|
Methods inherited from class org.apache.pig.EvalFunc |
finish, getCacheFiles, getInputSchema, getLogger, getPigLogger, getReporter, getReturnType, getSchemaName, getSchemaType, 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 |
opProvider
protected AlgebraicMathBase.KnownOpProvider opProvider
SUM
public SUM()
getArgToFuncMapping
public List<FuncSpec> getArgToFuncMapping()
throws FrontendException
- Description copied from class:
EvalFunc
- Allow a UDF to specify type specific implementations of itself. For example,
an implementation of arithmetic sum might have int and float implementations,
since integer arithmetic performs much better than floating point arithmetic. Pig's
typechecker will call this method and using the returned list plus the schema
of the function's input data, decide which implementation of the UDF to use.
- Overrides:
getArgToFuncMapping
in class EvalFunc<Double>
- Returns:
- A List containing FuncSpec objects representing the EvalFunc class
which can handle the inputs corresponding to the schema in the objects. Each
FuncSpec should be constructed with a schema that describes the input for that
implementation. For example, the sum function above would return two elements in its
list:
- FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.DOUBLE)))
- FuncSpec(IntSum.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.INTEGER)))
This would indicate that the main implementation is used for doubles, and the special
implementation IntSum is used for ints.
- Throws:
FrontendException
setOp
protected void setOp(AlgebraicMathBase.KNOWN_OP op)
getIntermed
public String getIntermed()
- Description copied from interface:
Algebraic
- Get the intermediate function.
- Specified by:
getIntermed
in interface Algebraic
- Returns:
- A function name of f_intermed. f_intermed should be an eval func.
The return type of f_intermed.exec() has to be Tuple
getFinal
public String getFinal()
- Description copied from interface:
Algebraic
- Get the final function.
- Specified by:
getFinal
in interface Algebraic
- Returns:
- A function name of f_final. f_final should be an eval func parametrized by
the same datum as the eval func implementing this interface.
Copyright © 2007-2012 The Apache Software Foundation