2

i have this in my Mapper code,where 'a' is a DoubleWritable array.

DoubleArrayWritable ad = new DoubleArrayWritable();
ad.set(a);
int row_id1=(int)row_id;
context.write(new LongWritable(row_id1),new Text(ad.toString()));

and i m just printing these inputs to reducer as output of reducer and i m getting this as output from reducer,

1   DoubleArrayWritable@e29820
2   DoubleArrayWritable@718242
3   DoubleArrayWritable@1ec58a
4   DoubleArrayWritable@3afb99

what am i missing ? i want output as

 1  2 3 4 7
 2  4 6 5 9
 3  4 5 7 3  
Divyendra
  • 111
  • 1
  • 5

2 Answers2

2

For the DoubleArrayWritable class, I'm assuming you're using the code from the accepted answer to this question. If that's the case, you'll need to implement toString to output in the format you want. Maybe something like:

public String toString() {
    if (data.length == 0) {
      return "";
    }

    StringBuilder sb = new StringBuilder();
    for (double d : data) {
        sb.append(d).append(" ");
    }

    //trim the trailing space
    sb.setLength(sb.length - 1);
    return sb.toString();
}

If you can live with a format like this:

[1, 2, 3, 4]

you can skip the toString method and do this instead:

context.write(new LongWritable(row_id1),new Text(Arrays.toString(ad.getData())));
Community
  • 1
  • 1
highlycaffeinated
  • 19,729
  • 9
  • 60
  • 91
  • thanks i did like that ... now can u please tell me how to get some prior data from a separate file which i can use to process my input data in reducer.like i have some sum stored in one or more file and now i want to divide every input i m getting from mapper in reducer by that sum. (i m new to HADOOP, please try to answer accordingly). – Divyendra Apr 27 '13 at 12:45
0

You can also try that:

context.write(new LongWritable(row_id1),new Text(String.valueOf(ad)));

I'm using that for string to Text conversions.

smttsp
  • 4,011
  • 3
  • 33
  • 62