com.hazelcast.mapreduce
Class Reducer<KeyIn,ValueIn,ValueOut>

java.lang.Object
  extended by com.hazelcast.mapreduce.Reducer<KeyIn,ValueIn,ValueOut>
Type Parameters:
KeyIn - key type of the resulting keys
ValueIn - value type of the incoming values
ValueOut - value type of the reduced values

@Beta
public abstract class Reducer<KeyIn,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.
Reducers are called in a threadsafe way so internal locking is not required.

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<String, Integer, Integer>
 {
   private int sum = 0;
   public void reduce( String key, Integer value )
   {
     sum += value;
   }

   public Integer finalizeReduce()
   {
     return sum;
   }
 }
 

Since:
3.2

Constructor Summary
Reducer()
           
 
Method Summary
 void beginReduce(KeyIn key)
          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 and retrieved the final reduced result.
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 reduces value needs to be hold internally in a member state of the Reducer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reducer

public Reducer()
Method Detail

beginReduce

public void beginReduce(KeyIn key)
This method is called before the first value is submitted to this Reducer instance. It can be used to setup any internal needed state before starting to reduce the actual values.

Parameters:
key - key of the mapped values

reduce

public 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 reduces value needs to be hold internally in a member state of the Reducer.

Parameters:
value - value to be reduced

finalizeReduce

public abstract ValueOut finalizeReduce()
finalizeReduce is called as last step for a reducing phase per key and retrieved the final reduced result.

Returns:
the final reduced result


Copyright © 2014 Hazelcast, Inc.. All Rights Reserved.