2017-09-01 108 views
0

作业中有两个输入文件,它们位于两个不同的目录中,在Hadoop job taking input files from multiple directories中,我们可以从多个目录中读取文件。这些文件具有相同的名称,但它们位于不同的名称文件夹中。 C1/part-0000 C2/part-0000 是否有可能在地图阶段检测文件?
像一些事情: public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { if (First file) { ... context.write(outputKey, outputValue); } } else { //Second file ... context.write(outputKey, outputValue); } } Hadoop作业从多个目录中获取输入文件并检测映射阶段中的每个目录

回答

0

检查它在安装阶段

@Override 
protected void setup(Context context) throws IOException, InterruptedException { 
    FileSplit split = (FileSplit) context.getInputSplit(); 
    Path path = split.getPath(); 
    String name = path.getName(); 
    ... 

不检查它在地图方法的每一行,因为是1个输入分流创建的每个映射。

相关问题