Reputation: 1
I am at learner level for Hadoop MapReduce
. Just trying , if I can provide an additional argument for program in JAVA. Basically I am trying to search a keyword in all input files, and want to provide the keyword as an argument, but Mapper interface
has only single map()
function, which do allow to add an additional argument.
Any help for this ?
Upvotes: 0
Views: 160
Reputation: 610
You can set arguments in your configuration
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
Inside mapper you can get this configuration from context and search for the keyword...
public void map(LongWritable key, Text value,Context context){
String keyword = context.getConfiguration().get("keyword");//does the job for you
}
Upvotes: 1
Reputation: 1273
There are lots of ways to do this, from passing parameters using a -D style parameter definition, to using hadoop configuration:
See here: http://www.thecloudavenue.com/2011/11/passing-parameters-to-mappers-and.html
Upvotes: 0