• Articles
  • Tutorials
  • Interview Questions

Combiner of MapReduce

What is MapReduce Combiner?

It is a localized optional reducer. It used mapper intermediate keys and applies a user method to combine the values in smaller segment of that particular mapper.

Many repeated keys are produced by maps. It is often useful to do a local aggregation process done by specifying combiner. The goal of the combiner is to decrease the size of the data. It has the same interface as reducer and often are the same class.

Method: conf.setCombinerClass(Reduce.class);
Work flow of combiner:

  • It has not predefined interface and  it implements reduce( ) method
  • Each map output key-value operated by combiner and the output key-value is same as reducer class
  • A combiner produces a summary of large data set.

Implementation: use  below input.txt input text file.
What do you mean by Object
 What do you know about Java
What is Java Virtual Machine
How Java enabled High Performance

Input: line by line text

Output : forms the key-value pairs

<1,   What do you mean by Object
 <2 ,  What do you know about Java
<3,   What is Java Virtual Machine
<4,   How Java enabled High Performance

Prepare for your MapReduce Interview by going through MapReduce Interview Questions.

Phases in combiner

There are three important phases in  the combiner

  • Map phase
  • Combiner phase
  • Reducer phase

Certification in Bigdata Analytics

Map phase:

Record reader gives the input to this phase and produces the output as another set of  key-value pairs.

Record reader is the first phase of MapReduce, it reads every line from the input text file as text.

<1,   What do you mean by Object>
 <2 ,  What do you know about Java>
<3,   What is Java Virtual Machine>
<4,   How Java enabled High Performance>
 Mapper class and map function

We  will get the output like


Combiner phase:

 This phase takes the map phase output as  input and the output of combiner phase is key-value collections pair.so,


Use following code to the class declaration of map phase, combiner phase and reduce phase.


Output: The expected output is


Become a Big Data Architect

Reduce phase:

This phase takes combiner phase output as input .
Use the following code for reduce  phase.

public static class IntSumReducer extends
      private IntWritable result = new IntWritable();
      public void reduce(Text key, Iterable values,Context context) throws IOException,
           int sum = 0;
           for (IntWritable val : values)
               sum += val.get();
        context.write(key, result);


Record  writer: Output
What                                      3
Do                                           2
You                                         2
Mean                                      1
By                                            1
Object                                     1
Know                                       1
About                                       1
Java                                         3
Is                                              1
Virtual                                     1
Machine                                  1
How                                         1
Enabled                                   1
High                                         1
Performance                           1

This blog will help you get a better understanding of Hadoop MapReduce – What it Refers To?

Course Schedule

Name Date Details
Big Data Course 20 Jul 2024(Sat-Sun) Weekend Batch
View Details
Big Data Course 27 Jul 2024(Sat-Sun) Weekend Batch
View Details
Big Data Course 03 Aug 2024(Sat-Sun) Weekend Batch
View Details

About the Author

Technical Reseach Analyst - Data Engineering

Abhijit is a Technical Research Analyst specializing in Deep Learning. He holds a degree in Computer Science with a focus on Data Science. Being proficient in Python, Scala, C++, Dart, and R, he is passionate about new-age technologies. Abhijit crafts insightful analyses and impactful content, bridging the gap between cutting-edge research and practical applications.