【问题标题】:Multiple output path (Java - Hadoop - MapReduce)多输出路径(Java - Hadoop - MapReduce)
【发布时间】: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 还有其他问题,但在我忘记之前,为了文明,让我们把我的发现放在这里:

http://archive.cloudera.com/cdh/3/hadoop-0.20.2+228/api/org/apache/hadoop/mapreduce/lib/output/MultipleOutputs.html

  • MultipleOutputs 不能代替 FormatOutputFormat。您可以使用 FormatOutputFormat 定义一个输出路径,然后您可以使用多个 MultipleOutput 添加更多路径。
  • addNamedOutput 方法:String namedOutput 只是一个描述词。
  • 您实际上在 write 方法中定义路径,String baseOutputPath arg。

【问题讨论】:

标签: java hadoop mapreduce output


【解决方案1】:

所以我做了你提到的最后一条评论中的方法,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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    相关资源
    最近更新 更多