0

I am running a MR code using Multioutputformat class. part**** is getting appended in the end of my output file. How can i avoid that?

public class MR_reducer extends Reducer {

private MultipleOutputs multipleOutputs;

@Override
protected void setup(Context context) throws IOException,
        InterruptedException {
    multipleOutputs = new MultipleOutputs(context);
}


@Override
protected void reduce(Text key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {
    for (Text value : values) {
        multipleOutputs.write(value, new Text(""), key.toString());
    }
}


@Override
protected void cleanup(Context context) throws IOException,
        InterruptedException {
    multipleOutputs.close();
}

}

Pooja3101
  • 701
  • 3
  • 8
  • 13

1 Answers1

0

This code snippet is working from me. You have few differences:

public static class Reduce extends Reducer<Text, Text, NullWritable, Text> {

    private MultipleOutputs<NullWritable, Text> multipleOutputs;

    protected void setup(Context context) throws IOException, InterruptedException {
        multipleOutputs = new MultipleOutputs<NullWritable, Text>(context);

    }

    public void reduce(Text key, Iterable<Text> values, Context output) throws IOException, InterruptedException {
        while (values.iterator().hasNext()) {
            multipleOutputs.write(NullWritable.get(), values.iterator().next(), key.toString());
        }
    }

    protected void cleanup(Context context) throws IOException, InterruptedException {
        multipleOutputs.close();
    }
}
Durga Viswanath Gadiraju
  • 3,896
  • 2
  • 14
  • 21