在一个作业中有两个输入文件,它们位于两个不同的目录中,在 Hadoop job taking input files from multiple directories 中,我们可以从多个目录读取文件。这些文件具有相同的名称,但它们位于不同名称的文件夹中。
C1/part-0000
C2/part-0000
有没有可能在map阶段检测文件?
就像是:
public void map(LongWritable key, Text value, Context 上下文)
抛出 IOException,InterruptedException {
如果(第一个文件){
...
context.write(outputKey, outputValue);
}
} 别的 {
//第二个文件
...
context.write(outputKey, outputValue);
}
}
最佳答案
在设置阶段检查
@Override
protected void setup(Context context) throws IOException, InterruptedException {
FileSplit split = (FileSplit) context.getInputSplit();
Path path = split.getPath();
String name = path.getName();
...
不要在每一行的 map 方法中检查它,因为每个映射器都是为 1 个输入拆分创建的。
关于file - Hadoop 作业从多个目录获取输入文件并在映射阶段检测每个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46003026/