java—在hadoop.io api的可写类中使用readfields()

uelo1irk  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(306)

我是个新手。我想知道在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;
 }
}

在上面的示例中,自定义recordreader使用set方法来设置x、y和z的值。最后,我们在Map器中得到这些值。但是对于writeable的readfealds和write()方法有什么需要呢??请。帮助

nzrxty8p

nzrxty8p1#

readfileds()和write()方法用于读写序列化数据,以便在网络上传输。
下面的问题解释了可写文件的必要性。
在hadoopmapreduce中为java类型设置可写 Package 器类的原因是什么?

相关问题