1

私はmap-reduceが初めてです。Hadoop でカスタム データ型を実装するときに、readfield と 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() メソッドは、ネットワーク経由で転送するシリアル化されたデータを読み書きするために使用されます。

次の質問は、書き込み可能なものの必要性を説明しています。

Hadoop MapReduce で Java 型の書き込み可能なラッパー クラスを使用する理由は何ですか?

于 2014-06-23T08:56:24.947 に答える