前面我们所分析的部分其实只是Hadoop作业提交的前奏曲,真正的作业提交代码是在MR程序的main里,RunJar在最后会动态调用这个main,在(二)里有说明。我们下面要做的就是要比RunJar更进一步,让作业提交能在编码时就可实现,就像Hadoop Eclipse Plugin那样可以对包含Mapper和Reducer的MR类直接Run on Hadoop。

  一般来说,每个MR程序都会有这么一段类似的作业提交代码,这里拿WordCount的举例:

Configuration conf = new Configuration();
String[] otherArgs
= new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println(
"Usage: wordcount <in> <out>");
System.exit(
2);
}
Job job
= new Job(conf, "word count");
job.setJarByClass(WordCount.
class);
job.setMapperClass(TokenizerMapper.
class);
job.setCombinerClass(IntSumReducer.
class);
job.setReducerClass(IntSumReducer.
class);
job.setOutputKeyClass(Text.
class);
job.setOutputValueClass(IntWritable.
class);
FileInputFormat.addInputPath(job,
new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job,
new Path(otherArgs[1]));
System.exit(job.waitForCompletion(
true) ? 0 : 1);

相关文章:

  • 2021-12-09
  • 2021-12-02
  • 2021-11-07
  • 2021-05-08
  • 2021-06-05
猜你喜欢
  • 2021-07-10
  • 2022-02-21
  • 2021-08-13
  • 2022-01-14
相关资源
相似解决方案