org.apache.pig.builtin
Class MAX

java.lang.Object
  extended by org.apache.pig.EvalFunc<T>
      extended by org.apache.pig.builtin.AlgebraicByteArrayMathBase
          extended by org.apache.pig.builtin.MAX
All Implemented Interfaces:
Accumulator<Double>, Algebraic

public class MAX
extends AlgebraicByteArrayMathBase

Generates the maximum of a set of values. This class implements Algebraic, so if possible the execution will performed in a distributed fashion.

MAX can operate on any numeric type and on chararrays. 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 MAX that uses integer arithmetic for comparing the data. The return type of MAX will match the input type.

MAX 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
protected static class AlgebraicMathBase.KNOWN_OP
           
protected static interface AlgebraicMathBase.KnownOpProvider
           
static class MAX.Final
           
static class MAX.Intermediate
           
 
Nested classes/interfaces inherited from class org.apache.pig.builtin.AlgebraicByteArrayMathBase
AlgebraicByteArrayMathBase.Initial
 
Nested classes/interfaces inherited from class org.apache.pig.EvalFunc
EvalFunc.SchemaType
 
Field Summary
protected  AlgebraicMathBase.KnownOpProvider opProvider
           
 
Fields inherited from class org.apache.pig.EvalFunc
log, pigLogger, reporter, returnType
 
Constructor Summary
MAX()
           
 
Method Summary
 List<FuncSpec> getArgToFuncMapping()
          Allow a UDF to specify type specific implementations of itself.
 String getFinal()
          Get the final function.
 String getIntermed()
          Get the intermediate function.
protected  void setOp(AlgebraicMathBase.KNOWN_OP op)
           
 
Methods inherited from class org.apache.pig.builtin.AlgebraicByteArrayMathBase
accumulate, cleanup, doTupleWork, exec, getInitial, getSeed, getValue, outputSchema
 
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
 

Field Detail

opProvider

protected AlgebraicMathBase.KnownOpProvider opProvider
Constructor Detail

MAX

public MAX()
Method Detail

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:
  1. FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.DOUBLE)))
  2. 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