【发布时间】:2013-04-01 08:28:03
【问题描述】:
我做了两个 MapReduce 作业,我希望第二个作业能够将我的结果写入两个不同的文件,位于两个不同的目录中。 在某种意义上,我想要类似于 FileInputFormat.addInputPath(.., multiple input path) 的东西,但是对于输出。
我是 MapReduce 的新手,我有一个专长,可以在 Hadoop 0.21.0 中编写我的代码
我在 Reduce 步骤中使用了context.write(..),但我看不到如何控制多个输出路径...
感谢您的宝贵时间!
我的第一份工作中的 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);
}
}
编辑:所以我按照你提到的最后一条评论中的方法,Amar。我不知道它是否有效,我的 HDFS 还有其他问题,但在我忘记之前,为了文明,让我们把我的发现放在这里:
- MultipleOutputs 不能代替 FormatOutputFormat。您可以使用 FormatOutputFormat 定义一个输出路径,然后您可以使用多个 MultipleOutput 添加更多路径。
- addNamedOutput 方法:String namedOutput 只是一个描述词。
- 您实际上在 write 方法中定义路径,String baseOutputPath arg。
【问题讨论】:
-
结帐
MultipleOutputs:archive.cloudera.com/cdh/3/hadoop-0.20.2+228/api/org/apache/… -
看起来像!我不知道我怎么没找到这个...我会试试谢谢!
-
还有一个问题:我们只能添加词来描述路径,比如说文档,为什么会这样?为什么我们不能放一个完整的路径,以便能够在不同的目录中输出?
-
是的,这是 MultipleOutputs 的问题!可悲的是,我现在也没有答案,请在此处查看我的问题:stackoverflow.com/questions/15100621/…
-
查看此答案的最后一条评论:stackoverflow.com/a/15102476/610305,看看是否有帮助。
标签: java hadoop mapreduce output