-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculateAverage.java
More file actions
executable file
·43 lines (35 loc) · 1.48 KB
/
CalculateAverage.java
File metadata and controls
executable file
·43 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package calculateAverage;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class CalculateAverage {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "CalculateAverage");
job.setJarByClass(CalculateAverage.class);
// set the class of each stage in mapreduce
job.setMapperClass(CalculateAverageMapper.class);
job.setCombinerClass(CalculateAverageCombiner.class);
job.setPartitionerClass(CalculateAveragePartitioner.class);
job.setSortComparatorClass(CalculateAverageKeyComparator.class);
job.setReducerClass(CalculateAverageReducer.class);
//
// set the output class of Mapper and Reducer
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(SumCountPair.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(DoubleWritable.class);
// set the number of reducer
job.setNumReduceTasks(2);
//
// add input/output path
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}