Commit 8b6cfef8 authored by mammadov's avatar mammadov

latest one

parent ef235174
package fr.eurecom.dsg.mapreduce;
import java.io.IOException;
import java.util.HashMap;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
......@@ -8,8 +11,13 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.io.*;
/**
* Word Count example of MapReduce job. Given a plain text in input, this job
......@@ -34,7 +42,7 @@ public class WordCountIMC extends Configured implements Tool {
job.setInputFormatClass(TextInputFormat.class);
// TODO: set map class and the map output key and value classes
job.setMapperClass(WCIMCMap.class);
job.setMapperClass(WCIMCMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
......@@ -52,7 +60,7 @@ public class WordCountIMC extends Configured implements Tool {
FileInputFormat.setInputPaths(job, inputPath);
// TODO: set the output path for the job results (to HDFS)
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
FileOutputFormat.setOutputPath(job, outputDir);
// TODO: set the number of reducers. This is optional and by default is 1
......@@ -87,6 +95,8 @@ class WCIMCMapper extends Mapper<LongWritable, // TODO: change Object to input k
Text, // TODO: change Object to output key type
IntWritable> { // TODO: change Object to output value type
HashMap<String,Integer> wordMap = new HashMap();
@Override
protected void map(LongWritable key, // TODO: change Object to input key type
Text value, // TODO: change Object to input value type
......@@ -105,7 +115,7 @@ class WCIMCMapper extends Mapper<LongWritable, // TODO: change Object to input k
}
}
}
}}
class WCIMCReducer extends Reducer<Text, // TODO: change Object to input key
// type
......@@ -119,8 +129,8 @@ class WCIMCMapper extends Mapper<LongWritable, // TODO: change Object to input k
Context context) throws IOException, InterruptedException {
// TODO: implement the reduce method (use context.write to emit results)
int sum=0;
for(IntWritable value : values) {
int sum = 0;
for (IntWritable value : values) {
sum += value.get();
}
context.write(key, new IntWritable(sum));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment