2015-04-08 56 views
0

爲例:罐子類ARG1參數3傳遞變量「ARGS」到地圖類

輸入格式ARG 1,ARG 2爲輸出格式是這樣的:

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

我需要發送ARG3「ARGS [2]」映射類.....

public class JoinMultiMap extends MapReduceBase 
    implements Mapper<LongWritable, Text, Text, Text> 
{ 
i need arg3 her 
} 

回答

1

您可以使用Configuration類這樣的設置和獲取自定義配置屬性:

在驅動程序代碼:

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); 
    } 
} 

從映射代碼:

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 
    } 
} 
+0

但什麼是getConf();在配置conf = getConf(); –

+0

'getConf()'只是一個方便的方法,由[Configured](https://hadoop.apache.org/docs/current/api/org/apache/hadoop/conf/Configured.html)類提供,由'setConf()'方法設置的配置對象。更多信息在這裏:http://stackoverflow.com/questions/14134865/what-is-the-usage-of-configured-class-in-hadoop-programs。 – Ashrith