我想用三个 Mapper
编写代码,其中两个将处理 ".csv"
文件,其他是 ".xml"
。我已经为来自 here 的 .xml
格式编写了 XmlInputFormat
现在我想知道我应该输入什么
job.setInputFormatClass(...);
还有我应该添加哪个以提供文件路径。
TextInputFormat.addInputPath(...)
TextOutputFormat.setInputPath(...)
或
TextInputFormat.addInputPath(...)
TextOutputFormat.setInputPath(...)
最佳答案
您应该考虑编写两个映射器,一个处理 .csv
文件,另一个处理 .xml
。但是,两个映射器都应生成相同类型
的key-value
,以便单个 reducer 对其进行处理。
下面是一个使用 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.class
类是对应的输入格式类。
关于java - 在 MapReduce 中调用具有不同 InputFormatClass 的多个 Mapper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49232274/