gpt4 book ai didi

file - Hadoop 作业从多个目录获取输入文件并在映射阶段检测每个文件

转载 作者:可可西里 更新时间:2023-11-01 15:54:03 26 4
gpt4 key购买 nike

在一个作业中有两个输入文件,它们位于两个不同的目录中,在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com