在map或reduce中
1.初始化在configure或setup方法中
MultipleOutputs.addMultiNamedOutput(conf, "prefix", TextOutputFormat.class, Text.class, Text.class);
multipleOutputs = new MultipleOutputs(conf);
2.在mapper或reducer中
OutputCollector<NullWritable,Text> collector = multipleOutputs.getCollector("prefix-", "partition1", reporter);
3.在close方法中
multipleOutputs.close();
这样这个reduce输出的文件名为prefix-partition1-00000
本文介绍了如何在MapReduce中实现多个输出的方法。具体步骤包括:首先,在configure或setup方法中初始化输出;其次,在mapper或reducer中使用MultipleOutputs获取指定前缀和分区的输出收集器;最后,在close方法中关闭MultipleOutputs确保所有数据被正确写出。
510

被折叠的 条评论
为什么被折叠?



