Home > DeveloperSection > Articles > MapReduce Reducer Class:

MapReduce Reducer Class:


Big Data Bigdata  Hadoop  Software Development 
Ratings:
0 Comment(s)
 150  View(s)
Rate this:

MapReduce Reducer Class:    


MapReduce API has two main classes which do the Map-Reduce task for us: Mapper class and Reducer class. Mapper class is use for performing mapping jobs whereas the reducer class is used to implement reduce jobs. Previously we examine the Mapper class and its methods. Now here we see Reducer class and his several methods.


The Reducer base class works very similarly to the Mapper class, and usually requires only Sub classes to override a single reduce method. Here is the cut-down class definition:

 

reduce Method :

 

public class Reducer<K2, V2, K3, V3>

 

{

       void reduce(K1 key, Iterable<V2> values, Reducer.Context context)

        throws IOException, InterruptedException

         {

          //our code goes here………………..

           …………………..

           …………………..

         }

}

 

 

Again, notice the class definition in terms of the broader data flow (the reduce method accepts K2/V2 as input and provides K3/V3 as output) while the actual reduce method takes only a single key and its associated list of values. The Context object is again the mechanism to output the result of the method.


This class also has the setup, run, and cleanup methods with similar default implementations as with the Mapper class that can optionally be overridden:


 setup method:

protected void setup( Reduce.Context context)

throws IOException, InterruptedException

This method is called once before any key/lists of values are presented to the reduce method. The default implementation does nothing.


cleanup method:

protected void cleanup( Reducer.Context context)

throws IOException, InterruptedException

This method is called once after all key/lists of values have been presented to the reduce method. The default implementation does nothing.

 

run method:

protected void run( Reducer.Context context)

throws IOException, InterruptedException

This method controls the overall flow of processing the task within JVM.

 

The default implementation calls the setup method before repeatedly calling the reduce method for as many key/values provided to the Reducer class, and then finally calls the cleanup method.


Don't want to miss updates? Please click the below button!

Follow MindStick