mapreduce 模板

/***
 * MapReduce Module
 * @author nele
 *
 */
public class ModuleMapReduce extends Configured implements Tool {

    // map class
    /**
     * 
     * @author nele
     *  TODO
     */
    public static class ModuleMapper extends
            Mapper<LongWritable, Text, LongWritable, Text> {

        @Override
        public void map(LongWritable key, Text value, Context context)
                throws IOException, InterruptedException {
            // TODO
        }

    }

    // reduce class
    /***
     * 
     * @author nele
     * TODO
     */
    public static class ModuleReducer extends
            Reducer<LongWritable, Text, LongWritable, Text> {

        @Override
        //TODO
        public void reduce(LongWritable key, Iterable<Text> values,
                Context context) throws IOException, InterruptedException {
            // TODO
        }

    }

    // run method
    public int run(String[] args) throws Exception {
        Configuration conf = super.getConf();

        // create job
        Job job = Job.getInstance(conf, this.getClass().getSimpleName());
        job.setJarByClass(this.getClass());

        // set input path
        Path inPath = new Path(args[0]);
        FileInputFormat.addInputPath(job, inPath);

        // map
        //TODO
        job.setMapperClass(ModuleMapper.class);
        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(Text.class);

        // conbile
        job.setCombinerClass(ModuleReducer.class);

        // reduce
        //TODO
        job.setReducerClass(ModuleReducer.class);
        job.setOutputKeyClass(LongWritable.class);
        job.setOutputValueClass(Text.class);

        // output
        Path outPath = new Path(args[1]);
        FileOutputFormat.setOutputPath(job, outPath);

        // submit
        return job.waitForCompletion(true) ? 0 : 1;
    }

    public static void main(String[] args) throws Exception {
//        args = new String[] {
//                "hdfs://bigdata5:8020/user/nele/data/input/wc.txt",
//                "hdfs://bigdata5:8020/user/nele/data/output/output3" };

        Configuration conf = new Configuration();

        int status = ToolRunner.run(conf, new ModuleMapReduce(), args);

        System.exit(status);
    }

}

源代码:http://git.oschina.net/nele/WordCount/blob/master/src/main/java/org/apache/hadoop/WordCount/ModuleMapReduce.java?dir=0&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fhadoop%2FWordCount%2FModuleMapReduce.java&oid=768c6be2ff31813e1adad92669ee83560e1728bc&sha=3ced0622511a75a24223c62cf937ca40c6449501

转载于:https://www.cnblogs.com/nele/p/5177540.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值