Passing Parameter from Driver Program to Map-Reduce Program using Conf object

Sometimes you may want to pass some information from Driver program to Mapper or Reducer program.In that case Configuration object can be your best friend.

1.In your driver program get access to your configuration object as shown below.Use conf.set(-,-) to set information.

Job job = new Job();
Configuration conf=job.getConfiguration();
conf.set("username", "prasad");
conf.set("password","1235");

2.From your Mapper or Reducer method,use the below snippet to access your information.

public void map/reduce(LongWritable key, Text value, Context context) throws IOException, InterruptedException
{
Configuration conf=context.getConfiguration();
String un=conf.get("username");
String pwd=conf.get("password");

//other logic goes here

}

Leave a Reply