Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Map extends Mapper<LongWritable, Text, Text, DoubleWritable> {
- //private final static DoubleWritable one = new DoubleWritable(1);
- private final static String emptyWords[] = { "" };
- @Override
- public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
- // TODO: à compléter
- String line = value.toString();
- // Une méthode pour créer des messages de log
- // LOG.info("MESSAGE INFO");
- String[] words = line.split(",");
- // La ligne est vide : on s'arrête
- if (Arrays.equals(words, emptyWords))
- return;
- //for (String word : words)
- try{
- context.write(new Text(words[5]), new DoubleWritable(Double.parseDouble(words[words.length-1])));
- }catch(RuntimeException e)
- {
- System.out.println(e);
- }
- }
- }
- public static class Reduce extends Reducer<Text, DoubleWritable, Text, DoubleWritable> {
- @Override
- public void reduce(Text key, Iterable<DoubleWritable> values, Context context)
- throws IOException, InterruptedException {
- // TODO: à compléter
- int sum = 0;
- for (DoubleWritable val : values)
- sum += val.get();
- context.write(key, new DoubleWritable(sum));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement