购买
下载掌阅APP,畅读海量书库
立即打开
畅读海量书库
扫码下载掌阅APP

4.7
默认Mapper和默认Reducer

如果没有给Job设置Mapper和Reducer,则将会使用默认的Mapper和Reducer。默认的Mapper和Reducer什么都不会做,只是进行文件的快速复制,如【代码4-8】所示。此代码中,并没有设置Mapper和Reducer类,将会使用默认的Mapper和Reducer类。

【代码4-8】DefaultMR.java /GVcrGPsXlT+v70O7cBhtQXF2R3SUU8h1ilP84epiU4BVnBzYHx1xHPVFC/oYew6

 
    1.  package org.hadoop.dft;
    2.  public class DefaultMR extends Configured implements Tool {
    3.      @Override
    4.      public int run(String[] args) throws Exception {
    5.          if(args.length!=2){
    6.             System.out.println("usage : <in> <out>");
    7.             return -1;
    8.         }
    9.         Configuration conf = getConf();
    10.        Job job = Job.getInstance(conf,"DefaultMR");
    11.        job.setJarByClass(this.getClass());
    12.        FileSystem fs = FileSystem.get(conf);
    13.        if(fs.exists(new Path(args[1]))){
    14.            fs.delete(new Path(args[1]),true);
    15.        }
    16.        FileInputFormat.setInputPaths(job,new Path(args[0]));
    17.        FileOutputFormat.setOutputPath(job,new Path(args[1]));
    18.        int code = job.waitForCompletion(true)?0:1;
    19.        return code;
    20.    }
    21.    public static void main(String[] args) throws  Exception {
    22.        int code = ToolRunner.run(new DefaultMR(),args);
    23.        System.exit(code);
    24.    }
    25. }
    26.
点击中间区域
呼出菜单
上一章
目录
下一章
×