Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to map function in Hadoop

Tags:

I am new to Hadoop. I want to access a command line argument from main function(Java program) inside the map function of the mapper class. Please suggest ways to do this.

like image 463
Pooja N Babu Avatar asked Dec 10 '11 14:12

Pooja N Babu


2 Answers

Hadoop 0.20, introduced new MR API, there is not much functionality difference between the new (o.a.h.mapreduce package) and old MR API (o.a.h.mapred) except that data can be pulled within the mappers and the reducers using the new API. What Arnon is mentioned is with the old API.

Check this article for passing the parameters using the new and old API.

like image 120
Praveen Sripati Avatar answered Sep 29 '22 16:09

Praveen Sripati


You can pass parameters by hanging them on the Configuration

 JobConf job = new JobConf(new Configuration(), TheJob.class);
 job.setLong("Param Name",longValue)

The Configuration class has few set methods (Long, Int, Strings etc.) so you can pass parameters of several types. In the map job you can get the configuration from the Context (getConfiguration)

like image 25
Arnon Rotem-Gal-Oz Avatar answered Sep 29 '22 17:09

Arnon Rotem-Gal-Oz