How to set an object as a value for map output in Hadoop MapReduce?

In Hadoop MapReduce for intermediate output (generated by map ()), I want the value for intermediate output to be the next object.

MyObject{ date:Date balance:Double } 

How can I do it. Should I create my own Writable Class?

I am new to MapReduce.

Thanks.

+4
java mapreduce hadoop hdfs distributed-computing
source share
1 answer

You can write your own type, which you can emit as a mapper value. But no matter what you want to fix as a value, you 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 use the Avro serialization infrastructure.

+8
source share

All Articles