Amazing technological breakthrough possible @S-Logix

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • +91- 81240 01111

Social List

How to write Map Reduce output to multiple directories in Hadoop?


This source code is applied when large dataset is required to split into subsets for efficient processing in single machine. Data into the different file is written using the MultipleOutputs Object available in hadoop.mapreduce package that writes the data depending on the reducer key. Before the output is written to a file, it is initialized in setup method.

Sample Code

import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;

public class ReducerClass extends Reducer<Text, Text, NullWritable, Text> {

private MultipleOutputs<NullWritable,Text> multioutput;


protected void setup(Context context) throws IOException, InterruptedException {


multioutput= new MultipleOutputs<NullWritable,Text> (context);




protected void reduce(Text key,Iterable<Text> value,Context context) throws IOException, InterruptedException {

String fileName = key.toString()+Constants.FILE_NAME_PREFIX;

for (Text val : value) {

multioutput.write(NullWritable.get(), val, fileName);



Write Map Reduce output to multiple directories in Hadoop