Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hadoop “传递论点”;args";从主类到映射类_Hadoop_Mapreduce_Command Line Arguments - Fatal编程技术网

Hadoop “传递论点”;args";从主类到映射类

Hadoop “传递论点”;args";从主类到映射类,hadoop,mapreduce,command-line-arguments,Hadoop,Mapreduce,Command Line Arguments,示例:jar类arg1 arg2 arg3 arg 1表示输入格式,arg 2表示如下输出格式: public static void main(String[] args) { FileInputFormat.addInputPath(conf, new Path(args[0])); FileOutputFormat.setOutputPath(conf, new Path(args[1])); . . . . } 我需要将arg3“args[2]”发送到映射类 public class

示例:jar类arg1 arg2 arg3

arg 1表示输入格式,arg 2表示如下输出格式:

public static void main(String[] args)
{
FileInputFormat.addInputPath(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
.
.
.
.
}
我需要将arg3“args[2]”发送到映射类

public class JoinMultiMap extends MapReduceBase
  implements Mapper<LongWritable, Text, Text, Text> 
{
i need arg3 her
}
公共类JoinMultiMap扩展了MapReduceBase
实现映射器
{
我需要她
}
您可以使用该类设置和获取如下自定义配置属性:

在您的驱动程序代码中:

import org.apache.hadoop.conf.Configuration;
// other imports ignored for brevity
// ...

public class YourDriver extends Configured implements Tool {
  public int run(String[] args) {
    Configuration conf = getConf();
    conf.set("yourcustom.property", args[2]);
    // other driver code ignored
    // ...
  }

  public static void main(String[] args)  {
    int res = ToolRunner.run(new Configuration(), new YourDriver(), args);
    System.exit(res);
  }
}
从映射器代码:

public class YourMapper extends Mapper<...> {
  private String yourArgument;

  @Override
    protected void setup(Context context) {
        Configuration c = context.getConfiguration();
        yourArgument = c.get("yourcustom.property");
    }

  @Override
  protected void map(...) {
    // use your argument
  }
}
公共类YourMapper扩展了Mapper{
私有字符串参数;
@凌驾
受保护的无效设置(上下文){
配置c=context.getConfiguration();
yourArgument=c.get(“yourcustom.property”);
}
@凌驾
受保护的空映射(…){
//运用你的论点
}
}
但是什么是getConf();在配置conf=getConf()中
getConf()
只是类提供的一个方便方法,它返回了由
setConf()
方法设置的配置对象。更多信息请点击此处:。