Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 888
shahalpk Avatar asked Feb 18 '23 04:02

shahalpk


1 Answers

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.

like image 51
Tariq Avatar answered Apr 06 '23 03:04

Tariq