3

我做了两个 MapReduce 工作,我希望第二个工作能够将我的结果写入两个不同的文件,位于两个不同的目录中。在某种意义上,我想要类似于 FileInputFormat.addInputPath(.., multiple input path) 的东西,但对于输出。

我对 MapReduce 完全陌生,我有一个特殊性,可以context.write(..)在我的 Reduce 步骤中使用的 Hadoop 0.21.0 中编写我的代码,但我不知道如何控制多个输出路径......

谢谢你的时间 !

我的第一份工作中的 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 还有其他问题,但在我忘记之前,为了文明,让我们把我的发现放在这里:

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 方法: String namedOutput 只是一个描述词。
  • 您实际上在 write 方法中定义路径,即 String baseOutputPath arg。
4

1 回答 1

2

所以我做了你提到的最后一条评论中的方法,Amar。我不知道它是否有效,我的 HDFS 还有其他问题,但在我忘记之前,为了文明,让我们把我的发现放在这里:

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 方法: String namedOutput 只是一个描述词。您实际上在 write 方法中定义路径,即 String baseOutputPath arg。

于 2013-05-18T01:43:01.027 回答