模板类编写好后写MapReduce程序,的模板类编写好以后只需要改参数就行了,代码如下:
1 package org.dragon.hadoop.mr.module; 2 3 import java.io.IOException; 4 5 import org.apache.hadoop.conf.Configuration; 6 import org.apache.hadoop.conf.Configured; 7 import org.apache.hadoop.fs.Path; 8 import org.apache.hadoop.io.LongWritable; 9 import org.apache.hadoop.io.Text; 10 import org.apache.hadoop.mapreduce.Job; 11 import org.apache.hadoop.mapreduce.Mapper; 12 import org.apache.hadoop.mapreduce.Reducer; 13 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 14 import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; 15 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 16 import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; 17 import org.apache.hadoop.mapreduce.lib.partition.HashPartitioner; 18 import org.apache.hadoop.util.Tool; 19 import org.apache.hadoop.util.ToolRunner; 20 21 /** 22 * 23 * ########################################### 24 * ############ MapReduce 模板类 ########## 25 * ########################################### 26 * 27 * @author ZhuXY 28 * @time 2016-3-13 下午10:21:06 29 * 30 */ 31 public class ModuleMapReduce extends Configured implements Tool { 32 33 /** 34 * Mapper Class 35 */ 36 public static class ModuleMapper extends 37 Mapper<LongWritable, Text, LongWritable, Text> { 38 39 @Override 40 protected void setup(Context context) throws IOException, 41 InterruptedException { 42 super.setup(context); 43 } 44 45 @Override 46 protected void map(LongWritable key, Text value, Context context) 47 throws IOException, InterruptedException { 48 super.map(key, value, context); 49 } 50 51 @Override 52 protected void cleanup(Context context) throws IOException, 53 InterruptedException { 54 super.cleanup(context); 55 } 56 } 57 58 /** 59 * Reducer Class 60 */ 61 public static class ModuleReducer extends 62 Reducer<LongWritable, Text, LongWritable, Text> { 63 64 @Override 65 protected void setup(Context context) throws IOException, 66 InterruptedException { 67 // TODO Auto-generated method stub 68 super.setup(context); 69 } 70 71 @Override 72 protected void reduce(LongWritable key, Iterable<Text> values, 73 Context context) throws IOException, InterruptedException { 74 // TODO Auto-generated method stub 75 super.reduce(key, values, context); 76 }