com.ebay.erl.mobius.core.function
Class Avg

java.lang.Object
  extended by com.ebay.erl.mobius.core.function.base.Projectable
      extended by com.ebay.erl.mobius.core.function.base.GroupFunction
          extended by com.ebay.erl.mobius.core.function.base.AggregateFunction
              extended by com.ebay.erl.mobius.core.function.base.SingleInputAggregateFunction
                  extended by com.ebay.erl.mobius.core.function.Avg
All Implemented Interfaces:
java.io.Serializable, org.apache.hadoop.conf.Configurable

public class Avg
extends SingleInputAggregateFunction

Computes the average value of the given inputColumn specified in Avg(Column).

Avg supports column in the following type, numerical type (Tuple.isNumericalType(byte) return true), date type (Tuple.isDateType(byte) return true), string, or writable.

In the case of string or writable type, this class try try to parse the number into double from its string representation. If it cannot be converted into such a number, an exception is thrown.

This product is licensed under the Apache License, Version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0. This product contains portions derived from Apache hadoop which is licensed under the Apache License, Version 2.0, available at http://hadoop.apache.org. © 2007 – 2012 eBay Inc., Evan Chiu, Woody Zhou, Neel Sundaresan

See Also:
Serialized Form

Field Summary
protected static byte _UNSET
           
protected  int roundingMode
          the rounding mode of the final output, default if BigDecimal.ROUND_HALF_UP.
protected  int scale
          the scale of the final output, default is 0.
protected  java.math.BigDecimal sum
          sum of the value of the selected column within a group.
protected  long total
          number of records in a group.
protected  byte valueType
          the type of the value of the input column
 
Fields inherited from class com.ebay.erl.mobius.core.function.base.SingleInputAggregateFunction
inputColumnName
 
Fields inherited from class com.ebay.erl.mobius.core.function.base.AggregateFunction
aggregateResult
 
Fields inherited from class com.ebay.erl.mobius.core.function.base.GroupFunction
rowsToBeOutputted
 
Fields inherited from class com.ebay.erl.mobius.core.function.base.Projectable
conf, hashCode, inputs, outputSchema, reporter, requireDataFromMultiDatasets
 
Constructor Summary
Avg(Column inputColumn)
          Create an Avg instance with scale set to 0 and rounding mode to BigDecimal.ROUND_HALF_UP
Avg(Column inputColumn, int scale, int roundingMode)
          Create an Avg instance with the given scale and rounding mode.
 
Method Summary
 void consume(Tuple tuple)
          consume a value within a group, to be implemented by sub-class.
protected  Tuple getComputedResult()
          Return the computed result in a Tuple.
 void reset()
          Empty previous result (rowsToBeOutputted), reset is called when the values within a group have been all iterated.
 
Methods inherited from class com.ebay.erl.mobius.core.function.base.AggregateFunction
getResult, newBigTupleList, output
 
Methods inherited from class com.ebay.erl.mobius.core.function.base.GroupFunction
getNoMatchResult, getRowsToBeOutputted
 
Methods inherited from class com.ebay.erl.mobius.core.function.base.Projectable
calledByCombiner, equals, getConf, getInputColumns, getOutputSchema, getParticipatedDataset, hashCode, init, isCombinable, requireDataFromMultiDatasets, setCalledByCombiner, setConf, setOutputSchema, setReporter, toString, useGroupKeyOnly
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_UNSET

protected static final byte _UNSET
See Also:
Constant Field Values

valueType

protected byte valueType
the type of the value of the input column


sum

protected java.math.BigDecimal sum
sum of the value of the selected column within a group.


total

protected long total
number of records in a group.


scale

protected final int scale
the scale of the final output, default is 0.


roundingMode

protected final int roundingMode
the rounding mode of the final output, default if BigDecimal.ROUND_HALF_UP.

Constructor Detail

Avg

public Avg(Column inputColumn)
Create an Avg instance with scale set to 0 and rounding mode to BigDecimal.ROUND_HALF_UP


Avg

public Avg(Column inputColumn,
           int scale,
           int roundingMode)
Create an Avg instance with the given scale and rounding mode.

Parameters:
scale - scale of the returned result
roundingMode - rounding mode (one of the BigDecimal#ROUND_XXX) of the returned result
Method Detail

consume

public void consume(Tuple tuple)
Description copied from class: GroupFunction
consume a value within a group, to be implemented by sub-class.

Specified by:
consume in class GroupFunction

getComputedResult

protected Tuple getComputedResult()
Description copied from class: SingleInputAggregateFunction
Return the computed result in a Tuple.

By default, the returned Tuple contains only one column, the name of the column is the first element in the Projectable.getOutputSchema().

Override this method if there is a need to output a Tuple with more than one column.

Overrides:
getComputedResult in class SingleInputAggregateFunction

reset

public void reset()
Description copied from class: GroupFunction
Empty previous result (rowsToBeOutputted), reset is called when the values within a group have been all iterated.

It is important to call super.reset() when override this method in a sub-class, fail to do so, will result in wrong result.

Overrides:
reset in class AggregateFunction