TECH SOLUTIONS

Click here to edit subtitle

Forums

Post Reply
Forum Home > Bigdata Learnings( Hadoop, HBase,Hive and other bigdata technologies) > Hadoop: Map Reduce: Using command line arguments in Mapper Class

Sourav Gulati
Site Owner
Posts: 83

In Map Reduce if we pass command line arguments it goes to driver class . However, if want to use it in Mapper class , it can be done as follows:

In Driver class , set the command line argument's value in the configuration object as follows:


public class TestDriver

{

    public static void main(String[] args) throws IOException,InterruptedException,ClassNotFoundException

    {

         Configuration conf = new Configuration();

         conf.set("val1", args[0]);

        conf.set("val2", args[1]);

  }

}

 

 Now , in Mapper , you can get these values as follows:

  

public class TestMapper extends Mapper

{

  public void map(Object key,Text value,Context context) throws IOException,InterruptedException

    {

        val1=context.getConfiguration().get("val1");

        val2=context.getConfiguration().get("val2");

 

    }

}

 

 

 

Click here for Other topics of BigData Technologies

 

January 22, 2013 at 5:30 AM Flag Quote & Reply

You must login to post.