hadoop - 启动 MapReduce 作业的不同方式

标签 hadoop java-8 mapreduce bigdata

在 Apache Hadoop 中仅使用 job.waitForCompletion(true) 方法和通过 ToolRunner.run(new MyClass(), args) 启动 map reduce 作业有什么区别?

我有一个 MapReduce 作业通过以下两种方式执行:

首先如下:

public class MaxTemperature extends Configured implements Tool {
  public static void main(String[] args) throws Exception {
      int exitCode = ToolRunner.run(new MaxTemperature(), args);
      System.exit(exitCode);
  }

  @Override
    public int run(String[] args) throws Exception {
        if (args.length != 2) {
              System.err.println("Usage: MaxTemperature <input path> <output path>");
              System.exit(-1);
            }
        System.out.println("Starting job");
        Job job = new Job();
        job.setJarByClass(MaxTemperature.class);
        job.setJobName("Max temperature");

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        job.setMapperClass(MaxTemperatureMapper.class);
        job.setReducerClass(MaxTemperatureReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        int returnValue = job.waitForCompletion(true) ? 0:1;

        if(job.isSuccessful()) {
            System.out.println("Job was successful");
        } else if(!job.isSuccessful()) {
            System.out.println("Job was not successful");           
        }
        return returnValue;
    }
}

第二个是:

public class MaxTemperature{

    public static void main(String[] args) throws Exception {

        if (args.length != 2) {
              System.err.println("Usage: MaxTemperature <input path> <output path>");
              System.exit(-1);
            }
        System.out.println("Starting job");
        Job job = new Job();
        job.setJarByClass(MaxTemperature.class);
        job.setJobName("Max temperature");

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        job.setMapperClass(MaxTemperatureMapper.class);
        job.setReducerClass(MaxTemperatureReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        int returnValue = job.waitForCompletion(true) ? 0:1;

        if(job.isSuccessful()) {
            System.out.println("Job was successful");
        } else if(!job.isSuccessful()) {
            System.out.println("Job was not successful");   

    }
}

两种方式的输出是一样的。但是我不明白两者之间有什么区别? 哪个比另一个更受欢迎?

最佳答案

这篇文章很好地解释了 ToolRunner 的使用:ToolRunner

关于hadoop - 启动 MapReduce 作业的不同方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41697229/

相关文章:

hadoop - 更改DataStax Enterprise中的化简器/映射器数量

hadoop - SemanticException行1:23无效的路径

java - 使用 Java 8 API 从 Set 到 Map

java - 基于 Java 8 中的 LocalDate.now() 获取一周的第一天的日期

hadoop - 在一行中组合多个PIG命令

hadoop - 如何编写 MapReduce Prog,其中 Reducers 的输出转到单个 Reducer

json - 使用 Pig 脚本将 Json 导入 Hbase

java - Hadoop ClassPath 单节点集群 Mac OS

sorting - thenComparing 与 thenComparingInt 的性能 - 使用哪个?

java - 如何在hadoop环境中添加外部Jar?