Sam
Sam

Reputation: 1

How to provide 3rd argument to Mapreduce program in addition to input and output location?

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

Answers (2)

Jijo
Jijo

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

grillp
grillp

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

Related Questions