I am new to map-reduce. I want to know what is the use of readfields and write methods when we implement our custom data types in hadoop? For example,
public class Point3D implements Writable {
public float x;
public float y;
public float z;
public Point3D(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
public Point3D() {
this(0.0f, 0.0f, 0.0f);
}
public void write(DataOutput out) throws IOException {
out.writeFloat(x);
out.writeFloat(y);
out.writeFloat(z);
}
public void readFields(DataInput in) throws IOException {
x = in.readFloat();
y = in.readFloat();
z = in.readFloat();
}
public String toString() {
return Float.toString(x) + ", "
+ Float.toString(y) + ", "
+ Float.toString(z);
}
public void set(float x, float y, float z)
{
this.x=x;
this.y=y;
this.z=z;
}
}
In the above example the custom recordreader uses the set method to set the values of x, y and z. So we finally, we get these values in the mapper. But whats the need of readfealds and write() methods from writable?? Pls. Help