com.hazelcast.mapreduce
ValueIn
- value type of the incoming valuesValueOut
- value type of the reduced values@Beta public abstract class Reducer<ValueIn,ValueOut> extends Object
The abstract Reducer class is used to build reducers for the Job
.
Reducers may be distributed inside of the cluster but there is always only one Reducer
per key.
Due to the fact that there is only one Reducer per key, mapped values needs to be
transmitted to one of the cluster nodes. To reduce the traffic costs between the
nodes, a Combiner
implementation can be added to the call which runs alongside
the mapper to pre-reduce mapped values into intermediate results.
A simple Reducer implementation could look like that sum-function implementation:
public class SumReducer implements Reducer<Integer, Integer> { private int sum = 0; public void reduce( Integer value ) { sum += value; } public Integer finalizeReduce() { return sum; } }
Constructor and Description |
---|
Reducer() |
Modifier and Type | Method and Description |
---|---|
void |
beginReduce()
This method is called before the first value is submitted to this Reducer instance.
|
abstract ValueOut |
finalizeReduce()
finalizeReduce is called as last step for a reducing phase per key.
|
abstract void |
reduce(ValueIn value)
This method is called to supply values to be reduced into a final reduced result.
The reduce method might be called multiple times so the eventually reduced value needs to be held internally in a member state of the Reducer. |
public void beginReduce()
public abstract void reduce(ValueIn value)
value
- value to be reducedpublic abstract ValueOut finalizeReduce()
Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.