I am new to map reduce and writing a reduce function to print the values in a Iterable. Below is my print function:
public class Reduce extends Reducer<Text, Text, Text, Text> {
protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
StringBuilder builder = new StringBuilder();
for (Text value : values) {
builder.append("<");
builder.append(value);
builder.append(",");
builder.append(key);
builder.append(">");
builder.append("\n");
context.write(new Text(builder.substring(0, builder.length())), key);
}
}
}
Output is:
Issue is that the values are getting repeated i.e. <2,1> is repeated 2 times... My requirement is after <2,1> I should directly get <3,1> and then <4,1>. In short all my should be unique.
My final output should be:
<2,1>
<3,1>
<4,1>
<3,2>
<4,2>
<1,2>
<4,3>
Please suggest.