Advertisement
mouhsineelachbi

MyReducer

Dec 9th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. package Topics;
  2.  
  3. import java.io.IOException;
  4.  
  5. import org.apache.hadoop.io.IntWritable;
  6. import org.apache.hadoop.io.Text;
  7. //import org.apache.hadoop.mapred.Reducer.*;
  8. import org.apache.hadoop.mapreduce.Reducer;
  9. //import org.apache.hadoop.mapreduce.Reducer.Context;
  10.  
  11. public class MyReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
  12.     private IntWritable result = new IntWritable();
  13.    
  14.     public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
  15.         int sum = 0;
  16.         for(IntWritable val:values){
  17.             sum += val.get();
  18.         }
  19.         result.set(sum);
  20.         context.write(key, result);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement