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

后端 未结 1 1546
忘掉有多难
忘掉有多难 2020-12-21 02:46

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.


MyOb         


        
相关标签:
1条回答
  • 2020-12-21 03:23

    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.

    0 讨论(0)
提交回复
热议问题