编写Hadoop程序驱动程序的多种方法 - 选择哪一种?

She*_*har 1 hadoop

我观察到有多种方法可以编写Hadoop程序的驱动方法.

雅虎的Hadoop教程中给出了以下方法

 public void run(String inputPath, String outputPath) throws Exception {
    JobConf conf = new JobConf(WordCount.class);
    conf.setJobName("wordcount");

    // the keys are words (strings)
    conf.setOutputKeyClass(Text.class);
    // the values are counts (ints)
    conf.setOutputValueClass(IntWritable.class);

    conf.setMapperClass(MapClass.class);
    conf.setReducerClass(Reduce.class);

    FileInputFormat.addInputPath(conf, new Path(inputPath));
    FileOutputFormat.setOutputPath(conf, new Path(outputPath));

    JobClient.runJob(conf);
  }
Run Code Online (Sandbox Code Playgroud)

这种方法在Hadoop The Definitive Guide 2012Oreilly的书中给出.

public static void main(String[] args) throws Exception {
  if (args.length != 2) {
    System.err.println("Usage: MaxTemperature <input path> <output path>");
    System.exit(-1);
  }
  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);
  System.exit(job.waitForCompletion(true) ? 0 : 1);
}
Run Code Online (Sandbox Code Playgroud)

在尝试Oreilly书中给出的程序时,我发现Job类的构造函数已被弃用.由于Oreilly的书基于Hadoop 2(纱线),我惊讶地发现他们使用了弃用的类.

我想知道每个人使用哪种方法?

Esw*_*apa 5

我使用前一种方法.如果我们改写run()方法,我们可以使用像-D,-libjars,-files等的hadoop jar选项.所有这些在几乎任何hadoop项目中都非常必要.不确定我们是否可以通过main()方法使用它们.