Created
April 6, 2014 19:27
-
-
Save sdpatil/10010445 to your computer and use it in GitHub Desktop.
WordCountReducer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.spnotes.hadoop; | |
| import java.io.IOException; | |
| import java.util.Iterator; | |
| import org.apache.hadoop.io.IntWritable; | |
| import org.apache.hadoop.io.Text; | |
| import org.apache.hadoop.mapreduce.Reducer; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable>{ | |
| Logger logger = LoggerFactory.getLogger(WordCountReducer.class); | |
| @Override | |
| protected void reduce(Text key, Iterable<IntWritable> values, | |
| Context context) | |
| throws IOException, InterruptedException { | |
| logger.debug("Entering WordCountReducer.reduce() " + this); | |
| int sum = 0; | |
| Iterator<IntWritable> valuesIt = values.iterator(); | |
| while(valuesIt.hasNext()){ | |
| sum = sum + valuesIt.next().get(); | |
| } | |
| logger.debug(key + " -> " + sum); | |
| context.write(key, new IntWritable(sum)); | |
| logger.debug("Exiting WordCountReducer.reduce()"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment