我有一个非常简单的“Hello world”风格的 map/reduce 作业。
public class Tester extends Configured implements Tool {
@Override
public int run(String[] args) throws Exception {
if (args.length != 2) {
System.err.printf("Usage: %s [generic options] <input> <output>\n",
getClass().getSimpleName());
ToolRunner.printGenericCommandUsage(System.err);
return -1;
}
Job job = Job.getInstance(new Configuration());
job.setJarByClass(getClass());
getConf().set("mapreduce.job.queuename", "adhoc");
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWritable.class);
job.setMapperClass(TesterMapper.class);
job.setNumReduceTasks(0);
return job.waitForCompletion(true) ? 0 : 1;
}
public static void main(String[] args) throws Exception {
int exitCode = ToolRunner.run(new Tester(), args);
System.exit(exitCode);
}
它实现了 ToolRunner,但运行时不解析参数。
$hadoop jar target/manifold-mapreduce-0.1.0.jar ga.manifold.mapreduce.Tester -conf conf.xml etl/manifold/pipeline/ABV1T/ingest/input etl/manifold/pipeline/ABV1T/ingest/output
15/02/04 16:35:24 INFO client.RMProxy: Connecting to ResourceManager at lxjh116-pvt.phibred.com/10.56.100.23:8050
15/02/04 16:35:25 WARN mapreduce.JobSubmitter: Hadoop command-line option parsing not performed. Implement the Tool interface and execute your application with ToolRunner to remedy this.
我可以验证没有添加配置。
有人知道为什么 Hadoop 认为 ToolRunner 没有实现吗?
$hadoop 版本 Hadoop 2.4.0.2.1.2.0-402
霍顿工厂
谢谢, 克里斯
最佳答案
由于您的问题在 Google 搜索此警告的顶部的速度非常快,因此我将在此处给出正确的答案:
正如 user1797538 你 所说:(对此感到抱歉)
user1797538: "The problem was the call to get a Job instance"
必须使用父类(super class) Configured。顾名思义,它已经配置好了,所以Tester类必须使用现有的Configuration,不能设置一个新的空Configuration。
如果我们在方法中提取作业创建:
private Job createJob() throws IOException {
// On this line use getConf() instead of new Configuration()
Job job = Job.getInstance(getConf(), Tester.class.getCanonicalName());
// Other job setter call here, for example
job.setJarByClass(Tester.class);
job.setMapperClass(TesterMapper.class);
job.setCombinerClass(TesterReducer.class);
job.setReducerClass(TesterReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
// adapt this to your needs of course.
return job;
}
javadoc 中的另一个示例:org.apache.hadoop.util.Tool
还有 Javadoc:Configured.getConf()
关于java - 即使已实现,也会收到工具界面警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28333080/