My mapper code-
public class MapperClass extends Mapper<LongWritable, Text, Text, IntWritable> {
@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String ss = value.toString();
for(String word : ss.split(" "))
{
context.write(new Text(word),new IntWritable(1));
}
}
}
My reducer code
public class ReducerClass extends Reducer<Text, IntWritable, Text, IntWritable> {
@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
while(values.iterator().hasNext())
{
IntWritable i= values.iterator().next();
sum++;
}
context.write(key, new IntWritable(sum));
}
}
My output file is --
1 1 1 1 1 1 2 1 2 1 3 1
Why is it showing this type of output instead of the following?
1 2 2 2 3 1
Aucun commentaire:
Enregistrer un commentaire