public static class MapClass extends MapReduceBase implements
Mapper<LongWritable, Text, Text, IntWritable> {
private Text word = new Text();
public void map(LongWritable key, Text value,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException {
String line = value.toString();
String num = Integer.parseInt(line);
IntWritable one = new IntWritable(num);
word.set(“key”);
output.collect(word, one);
}
}
public static class Reduce extends MapReduceBase implements
Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOException {
int sum = 0;
int count = 0;
int avg = 0;
while (values.hasNext()) {
sum += values.next().get();
count++;
}
avg = sum / count;
output.collect(key, new IntWritable(count));
}
}
see the output.collect() specifically, i am printing key & count values..
For any input file, the output is
key 2
please help me…. (how the output is always 2 even if 100 nos as input??)
If you want to test your code,
here is a JUNIT test using the mockito framework, assuming you have your reducer and mapper in the example class.