java - 在 hadoop.io api 的可写类中使用 readFields()

标签 java hadoop mapreduce writable

我是 map-reduce 的新手。我想知道当我们在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() 方法需要什么? 请。帮助

最佳答案

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

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

What is the reason for having Writable wrapper classes in Hadoop MapReduce for Java types?

关于java - 在 hadoop.io api 的可写类中使用 readFields(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24361094/

相关文章:

java - 从Processing3.4插入HTML(java)

hadoop - HDInsight Azure Blob存储数据更新

python - 这个字典作业在做什么?

multithreading - 如何并行执行自定义函数公式,同时保持Google表格的可共享性和非许可性?

hadoop - 将表名从文件传递到 oozie 工作流

hadoop - Hadoop mapreduce设计/路由映射器和化简器一次完成

java - 关于 Java 模块和 Maven 的 Eclipse 2019-03

java - 如何防止 Spring Boot Devtools 缓存少量文件

java - 使用 volatile 确保 Java 中共享(但不是并发)数据的可见性

hadoop - 我们应该遵循Debian Hadoop发行版还是转向由Cloudera,Hortonworks,MapR等提供的其他发行版?