多输出路径(Java – Hadoop – MapReduce)

我做两个MapReduce作业,我希望第二个作业能够将我的结果写入两个不同的目录中的两个不同的文件中。 我想在某种意义上类似于FileInputFormat.addInputPath(..,多输入路径),但是对于输出。

我是MapReduce的新手,我有一个特殊性来编写我的代码在Hadoop 0.21.0中我在我的Reduce步骤中使用了context.write(..) ,但是我没有看到如何控制多个输出路径.. 。

谢谢你的时间 !

我的reduceCode来自我的第一份工作,向您展示我只知道如何输出(它进入/../part*文件。但现在我想要的是能够为不同的输出指定两个精确文件,具体取决于钥匙) :

 public static class NormalizeReducer extends Reducer { public void reduce(LongWritable key, Iterable 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。

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