我在访问Hadoop Tool实现的命令行配置参数时遇到了问题。
我使用以下命令执行:hadoop jar <jar> <mainclass> -D SomeProperty=NewValue
run(String[] args)方法开始于:
Configuration configuration = this.getConf();
configuration.set("SomeProperty", "DefaultValue");
Options options = new Options();
GenericOptionsParser parser = new GenericOptionsParser(configuration, options, args);
args = parser.getRemainingArgs();
if (configuration.get("SomeProperty").equals("DefaultValue"))
return 1; //Will always return here unless the default value is overridden属性SomeProperty从未被设置为NewValue。没有默认值的新属性在配置中设置得很好,因此问题似乎在于命令行参数没有覆盖默认配置值。
为什么会发生这种情况?我能改变这种行为吗?
编辑:为了澄清,如果我用hadoop jar <jar> <mainclass> -D SomeProperty=NewValue -D SecondProperty=OtherValue调用jar命令,则SecondProperty将在配置中被适当设置,而SomeProperty不会被设置,两者之间的唯一区别是,当使用GenericOptionsParser时,配置已经调用了set("SomeProperty", "DefaultValue")。
发布于 2016-03-09 15:14:16
这是我对ToolRunner责任的误解。
文件说明(重点是地雷):
在使用给定的泛型参数进行解析之后,由Tool.run(String[])运行给定的工具。使用给定的配置,或者生成一个如果为null的配置。使用可能修改的conf版本设置该工具的配置。
我错误地认为使用泛型选项解析器是Tool的责任。
https://stackoverflow.com/questions/35877159
复制相似问题