How Java Hadoop Mapper can send multiple values

hadoop, java, mapper

Solution

The simplest I can think of is just to merge them into a single string:

output.collect(custID, prodID + "," + rate);

Then, split if back up on the reducers.

If you post a little more code from your mapper maybe we could give a better example.

UPDATE: That said, you asked for the best way. The most correct way is probably to create a separate class grouping `prodID` and `rate` together and send that.

Problem

My mapper needs to send the following tuples: ``` <custID,prodID,rate> ``` And I want to send to reducer the custID as a key, and as value the prodID and rate together, as they are needed for the reduce phase. Which is the best way of doing this? ``` public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String[] col = value.toString().split(","); custID.set(col[0]); data.set(col[1] + "," + col[2]); context.write(custID, data); } public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { for (Text val : values) { String[] temp = val.toString().split(","); Text rate = new Text(temp[1]); result.set(rate); context.write(key, result); } } ```

Original source

Related problems