I am very new to hadoop. i have done with word-count and now I want to do a modification.
I want to get the word that has occurred most in a text file. If, normal word count program gives a output :
a 1
b 4
c 2
I want to write program that will give me output only
b 4
here my reducer function ::
public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable>
{
int max_sum=0;
Text max_occured_key;
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException
{
int sum = 0;
for (IntWritable val : values)
{
sum += val.get();
}
if(sum > max_sum)
{
max_sum = sum;
max_occured_key = key;
}
context.write(max_occured_key, new IntWritable(max_sum));
//context.write(key, new IntWritable(sum));
}
}
but it is not giving the right output. Can anyone help plz ?