除输入输出位置外,如何为Mapreduce程序提供第三个参数?

时间:2014-01-11 08:46:41

标签: mapreduce

我是Hadoop MapReduce的学习者级别。试试,如果我可以为JAVA中的程序提供额外的参数。基本上我试图在所有输入文件中搜索关键字,并希望提供关键字作为参数,但Mapper interface只有一个map()函数,它允许添加一个额外的参数。

对此有何帮助?

2 个答案:

答案 0 :(得分:1)

您可以在配置中设置参数

Configuration conf = new Configuration();
conf.set("keyword","bob");
//bob can also be passed as an argument
//conf.set("keyword",args[3]); * note that both are string arguments

在内部映射器中,您可以从上下文中获取此配置并搜索关键字...

public void map(LongWritable key, Text value,Context context){
    String keyword = context.getConfiguration().get("keyword");//does the job for you
}

答案 1 :(得分:0)

有很多方法可以做到这一点,从使用-D样式参数定义传递参数到使用hadoop配置:

见这里:http://www.thecloudavenue.com/2011/11/passing-parameters-to-mappers-and.html

相关问题