How do i set an Object as the Value for Map output in Hadoop MapReduce?

為{幸葍}努か 提交于 2019-12-18 08:53:21

问题


In the Hadoop MapReduce, for the intermediate Output (generated by the map()), i want the Value for the Intermediate output to be the following object.


MyObject{
  date:Date
  balance:Double
}

How would i do this. Should i create my own Writable Class?

I am a newbie to MapReduce.

Thanks.


回答1:


You can write your custom type which you can emit as the mapper value. But whatever you want to emit as value, must implement the Writable Interface. You can do something like this :

public class MyObj implements WritableComparable<MyObj>{

    private String date;
    private Double balance;

    public String getDate() { return date;}
    public Double getBalance() { return balance;}

    @Override
    public void readFields(DataInput in) throws IOException {

        //Define how you want to read the fields
        }
    @Override
    public void writeFields(DataOutput out) throws IOException {

        //Define how you want to write the fields
    }
        .......
        .......
        .......

}

Alternatively you can make use of Avro serialization framework.



来源:https://stackoverflow.com/questions/13877077/how-do-i-set-an-object-as-the-value-for-map-output-in-hadoop-mapreduce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!