代码之家  ›  专栏  ›  技术社区  ›  Ayush Goyal

在MapReduce中使用不同的InputFormatClass调用多个映射器

  •  0
  • Ayush Goyal  · 技术社区  · 8 年前

    我想用三个 Mapper 其中两个将处理 ".csv" 文件其他is ".xml" 。我写过 XmlInputFormat 对于 .xml 格式来自 here

    现在我想知道我应该输入什么

    job.setInputFormatClass(...);
    

    以及我应该添加哪些来提供文件路径。

     TextInputFormat.addInputPath(...)
     TextOutputFormat.setInputPath(...)
    

    TextInputFormat.addInputPath(...)
    TextOutputFormat.setInputPath(...)
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Gyanendra Dwivedi    8 年前

    您应该考虑编写两个映射器,一个处理 .csv 文件和其他 .xml 。但是,两个映射器都应该生成 key-value 属于 same type ,用于单个减速器处理。

    下面是一个使用 org.apache.hadoop.mapred.lib.MultipleInputs 对于相同的:

    MultipleInputs.addInputPath(jobConf, 
                         new Path(csvFilePath),       
                         SequenceFileInputFormat.class, 
                         CSVProcessingMapper.class);
    MultipleInputs.addInputPath(jobConf, 
                         new Path(xmlFilePath), 
                         XmlInputFormat.class, 
                         XMLProcessingMapper.class);
    

    在这里 CSVProcessingMapper.class XmlInputFormat.class CSV XML 正在处理映射器。您可以为不同的输入类型使用尽可能多的映射器。 类似地 SequenceFileInputFormat.class XmlInputFormat。班 类是相应的输入格式类。

    推荐文章