package FlowCount;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowCountMapper extends Mapper<LongWritable, Text, Text, LongWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] oneLine = value.toString().split("\\s+");
        try {
            long upFlow = Long.parseLong(oneLine[1]);
            long downFlow = Long.parseLong(oneLine[2]);
            long sumFlow = upFlow + downFlow;

            context.write(new Text(oneLine[0]), new LongWritable(sumFlow));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
