4

Possible Duplicate:
MultipleOutputFormat in hadoop

I want to write the files according to months using map-reduce in hadoop. If data is from January month then the data should be wriiten in jan-file and likewise for each month there should be seperate file.

How Can I create such file in hadoop mapredude. I am trying for recursive map-reduce but not getting how to implement it?

Pls suggest me some solution.

Thanks.

Community
  • 1
  • 1
Bhavesh Shah
  • 3,299
  • 11
  • 49
  • 73

1 Answers1

5

Use the MultipleOutputFormat class, the output file name can be deduced from the key and the reducer output value from the reducer. MultipleOutputFormat#generateFileNameForKeyValue has to be implemented in the user defined OutputFormat class.

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 
    }
}
Praveen Sripati
  • 32,799
  • 16
  • 80
  • 117
  • Does not work with latest version of Hadoop (new mapreduce library instead of the old mapred). That's why I downvoted. – Tony Dec 16 '13 at 03:09