Skip to content

Instantly share code, notes, and snippets.

Created August 26, 2012 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3475609 to your computer and use it in GitHub Desktop.
Save anonymous/3475609 to your computer and use it in GitHub Desktop.
Data Intensive Text Processing with MapReduce #3 figure3.8 Reducer
package info.moaikids.mapred.reduce;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class Figure38Reducer extends
Reducer<Text, IntWritable, Text, IntWritable> {
static final int MIN = 1;
@Override
protected void reduce(Text key, Iterable<IntWritable> values,
Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable value : values) {
sum += value.get();
}
if (sum > MIN) {
context.write(key, new IntWritable(sum));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment