【问题标题】:Hadoop job taking input files from multiple directories and detecting each one in map phaseHadoop 作业从多个目录获取输入文件并在映射阶段检测每个文件
【发布时间】:2017-09-01 14:59:14
【问题描述】:

在作业中有两个输入文件,它们位于两个不同的目录中,在Hadoop job taking input files from multiple directories 中,我们可以从多个目录中读取文件。这些文件具有相同的名称,但它们位于不同名称的文件夹中。 C1/part-0000 C2/part-0000 是否可以在 map 阶段检测文件?
就像是: 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); } }

【问题讨论】:

    标签: file hadoop input mapreduce


    【解决方案1】:

    在设置阶段检查它

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

    不要在 map 方法中为每一行检查它,因为每个映射器都是为 1 个输入拆分创建的。

    【讨论】:

      猜你喜欢
      • 2011-06-03
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-01-06
      相关资源
      最近更新 更多