1

我是地图减少的新手。我想知道当我们在hadoop中实现我们的自定义数据类型时,readfields和write方法有什么用?例如,

     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;
 }
}

在上面的示例中,自定义记录读取器使用 set 方法来设置 x、y 和 z 的值。所以我们最终,我们在映射器中获得了这些值。但是可写的 readfealds 和 write() 方法需要什么?请。帮助

4

1 回答 1

1

readFileds() 和 write() 方法用于读取和写入序列化数据以通过网络传输。

以下问题解释了对可写文件的需求。

在 Java 类型的 Hadoop MapReduce 中具有可写包装类的原因是什么?

于 2014-06-23T08:56:24.947 回答