我做了两项 MapReduce 作业,我希望第二项作业能够将结果写入两个不同目录中的两个不同文件中。
我想要某种类似于 FileInputFormat.addInputPath(.., multiple input path) 的东西,但对于输出。
我对 MapReduce 完全陌生,并且我有一个特殊性,就是在 Hadoop 0.21.0 中编写我的代码
我用context.write(..)
在我的Reduce步骤中,但我不知道如何控制多个输出路径......
谢谢你的时间 !
我的第一份工作中的reduceCode,向您展示我只知道如何输出(它进入 /../part* 文件。但现在我想要的是能够为不同的输出指定两个精确文件,具体取决于钥匙) :
public static class NormalizeReducer extends Reducer<LongWritable, NetflixRating, LongWritable, NetflixUser> {
public void reduce(LongWritable key, Iterable<NetflixRating> values, Context context) throws IOException, InterruptedException {
NetflixUser user = new NetflixUser(key.get());
for(NetflixRating r : values) {
user.addRating(new NetflixRating(r));
}
user.normalizeRatings();
user.reduceRatings();
context.write(key, user);
}
}
EDIT:所以我按照你提到的最后一条评论中的方法做了,阿马尔。我不知道它是否有效,我的 HDFS 还有其他问题,但在我忘记之前,为了文明,让我们把我的发现放在这里:
http://archive.cloudera.com/cdh/3/hadoop-0.20.2+228/api/org/apache/hadoop/mapreduce/lib/output/MultipleOutputs.html http://archive.cloudera.com/cdh/3/hadoop-0.20.2+228/api/org/apache/hadoop/mapreduce/lib/output/MultipleOutputs.html
- MultipleOutputs 不能代替 FormatOutputFormat。您可以使用 FormatOutputFormat 定义一个输出路径,然后可以使用多个 MultipleOutputs 添加更多输出路径。
- addNamedOutput方法:字符串namedOutput只是一个描述的单词。
- 您实际上在 write 方法中定义路径,即 String baseOutputPath arg。