Hadoop adding numbers

**a 10 20 30 a 60
b 155
c 50
b 20 45 90
z 30 10 10
The above same is tab separated text file . I need total sum of numbers row wise . and the output should be like
I tried using the following mapper and reducer code but its failing . Can Anyone correct the code please*

Mapper code :

public class WordMapper extends MapReduceBase implements Mapper{

public void map(LongWritable key, Text value,
        OutputCollector<Text, IntWritable> output, Reporter arg3)
        throws IOException {
    String s = value.toString();
        for(String word:s.split("t")){
                output.collect(new Text(word),new IntWritable(1));
    // TODO Auto-generated method stub



Reducer Code:

public class WordReducer extends MapReduceBase implements Reducer{

public void reduce(Text key, Iterator<IntWritable> values,
        OutputCollector<Text, IntWritable> output, Reporter reporter)
        throws IOException {
    int sum = 0;
        if values != null{
        sum += values.next().get();
    output.collect(key, new IntWritable(sum));


Source: apache

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.