error with interface writable in hadoop

203 Views Asked by At

I have create a class VectorWritable which implements the interface Writable. I am trying to write a VectorWritable object to the output file but i am getting this: VectorWritable@1355b88b. Here is my write method:

public void write(DataOutput out) throws IOException {  
   getVectorString().write(out);
}

The function getVectorString() gives a Text object.

1

There are 1 best solutions below

2
On

I don't have 50 rep to comment, so I will write it as an answer.

How do you create this Text object inside getVectorString()? Aren't you invoking default toString() method on the VectorWritable object, which returns strings like "VectorWritable@1355b88b" unless you override it to return a more useful string which describes your object?

EDIT:

According to your comment Text vectorString is a member of VectorWritable class, you set this Text object in set method so i guess that the set method is also inside VectorWritable, and it is not a static method, so why do you pass a VectorWritable object to it? It looks like you could invoke this set method on one VectorWritable object, pass another to it, and have vectorString not matching surrounding VectorWritable object.

How do you write VectorWritable to the output? Do you invoke the write method which you posted inside your question? Because this output VectorWritable@1355b88b looks like you pass VectorWritable as an argument to a method which invokes its default toString() method which would return string like VectorWritable@1355b88b.

Writable interface is used to serialize objects. So you can write the object to an output, and read it back, but with your implementation it would be hard to parse the string you create and read the object back. Example of implementation

   public void write(DataOutput out) throws IOException {
     out.writeInt(counter);
     out.writeLong(timestamp);
   }

   public void readFields(DataInput in) throws IOException {
     counter = in.readInt();
     timestamp = in.readLong();
   }