<分区>
Possible Duplicate:
MultipleOutputFormat in hadoop
我想在 hadoop 中使用 map-reduce 根据月份编写文件。如果数据来自一月份,那么数据应该写在 jan 文件中,同样每个月都应该有单独的文件。
如何在 hadoop mapredude 中创建这样的文件。我正在尝试递归 map-reduce 但不知道如何实现它?
请给我一些解决方案。
谢谢。
<分区>
Possible Duplicate:
MultipleOutputFormat in hadoop
我想在 hadoop 中使用 map-reduce 根据月份编写文件。如果数据来自一月份,那么数据应该写在 jan 文件中,同样每个月都应该有单独的文件。
如何在 hadoop mapredude 中创建这样的文件。我正在尝试递归 map-reduce 但不知道如何实现它?
请给我一些解决方案。
谢谢。
最佳答案
使用 MultipleOutputFormat class,输出文件名可以从reducer的键和reducer输出值推导出来。 MultipleOutputFormat#generateFileNameForKeyValue必须在用户定义的 OutputFormat 类中实现。
static class MyMultipleOutputFormat extends MultipleOutputFormat<Text, Text> {
protected String generateFileNameForKeyValue(Text key, Text value, String name) {
String keyString = key.toString();
String valueString = value.toString();
#return a combination of keyString and valueString
}
}
关于hadoop - 在 Hadoop 中的多个文件中写入输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8641461/