0

exemple : jar class arg1 arg2 arg3

arg 1 for input format , arg 2 for output format like this :

public static void main(String[] args)
{
FileInputFormat.addInputPath(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
.
.
.
.
}

i need to send arg3 "args[2]" to map class .....

public class JoinMultiMap extends MapReduceBase
  implements Mapper<LongWritable, Text, Text, Text> 
{
i need arg3 her
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

1 Answers1

2

You could use the Configuration class to set and get custom configuration properties like this:

In your Driver code:

import org.apache.hadoop.conf.Configuration;
// other imports ignored for brevity
// ...

public class YourDriver extends Configured implements Tool {
  public int run(String[] args) {
    Configuration conf = getConf();
    conf.set("yourcustom.property", args[2]);
    // other driver code ignored
    // ...
  }

  public static void main(String[] args)  {
    int res = ToolRunner.run(new Configuration(), new YourDriver(), args);
    System.exit(res);
  }
}

From the Mapper code:

public class YourMapper extends Mapper<...> {
  private String yourArgument;

  @Override
    protected void setup(Context context) {
        Configuration c = context.getConfiguration();
        yourArgument = c.get("yourcustom.property");
    }

  @Override
  protected void map(...) {
    // use your argument
  }
}
Ashrith
  • 6,745
  • 2
  • 29
  • 36
  • but what is getConf(); in Configuration conf = getConf(); – Hammouche Zane Apr 13 '15 at 23:04
  • `getConf()` is just a convenience method provided by the [Configured](https://hadoop.apache.org/docs/current/api/org/apache/hadoop/conf/Configured.html) class which gives back the configuration object set by `setConf()` method. More info here: http://stackoverflow.com/questions/14134865/what-is-the-usage-of-configured-class-in-hadoop-programs. – Ashrith Apr 14 '15 at 03:58