hadoop命令行-d选项不起作用

0x6upsns  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(330)

我尝试在hadoop中使用-d命令行选项传递变量(而不是属性) -Dmapred.mapper.mystring=somexyz . 我可以在驱动程序中设置conf属性,并在mapper中读取它。所以我可以用它来传递字符串作为附加参数,并在驱动程序中设置它。但是我想看看-d选项是否也可以用来做同样的事情
我的命令是:

$HADOOP_HOME/bin/hadoop jar  /home/hduser/Hadoop_learning_path/toolgrep.jar /home/hduser/hadoopData/inputdir/ /home/hduser/hadoopData/grepoutput -Dmapred.mapper.mystring=somexyz

驱动程序

String s_ptrn=conf.get("mapred.mapper.regex");

system.out.println(“debug:in tool class mapred.mapper.regex”+s\u ptrn+“\n”);提供空值
但这是有效的

conf.set("DUMMYVAL","100000000000000000000000000000000000000"); in driver is read properly in mapper by get method.

我的问题是,如果所有的互联网都说我可以使用-d选项,那么为什么我不能呢?这是不是不能用于任何参数而只能用于属性?我们可以把它放在我应该在驱动程序中读取然后使用它的文件中读取哪些内容?
像这样的

Configuration conf = new Configuration();
conf.addResource("~/conf.xml");

在驱动程序中,这是唯一的方法。

cgh8pdjw

cgh8pdjw1#

正如托马斯所写,你错过了空间。你也在传递变量 mapred.mapper.mystring 在您的cli中,但在您尝试获取的代码中 mapred.mapper.regex . 如果要使用-d参数,应该使用工具接口。更多信息在这里-hadoop:为mapreduce驱动程序实现工具接口。
或者您可以像这样解析cli参数:

@Override
public int run(String[] args) throws Exception {
Configuration conf = this.getConf();

String[] otherArgs = new GenericOptionsParser(conf,args).getRemainingArgs();
while (i<otherArgs.length) {
        if (otherArgs[i].equals("-x")) {
            //Save your CLI argument
            yourVariable = otherArgs[++i];
}
//then save yourVariable into conf for using in map phase

你的命令可以是这样的:

$HADOOP_HOME/bin/hadoop jar /home/hduser/Hadoop_learning_path/toolgrep.jar /home/hduser/hadoopData/inputdir/ /home/hduser/hadoopData/grepoutput -x yourVariable

希望有帮助

相关问题