mapreduce序列化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/poppy_rain/article/details/84896447

1.   hadoop的序列化(Writable)比jdk的序列化(Serializable)更加简洁高效

2.   基本序列化类型

  • LongWritable
  • IntWritable
  • nullWritable
  • Text

3.    Bean序列化

因为maprduce的shuffle过程要对key比较排序,所以,如果key是bean,就要对bean进行序列化

  • 实现WritableComparable
TextBeanSer implements WritableComparable<TextBean> 
  • 序列化方法
public void write(DataOutput out) throws IOException {
    out.writeLong(a);
    out.writeFloat(b);
}
  • 反序列化方法(和序列化顺序一致)
public void readFields(DataInput in) throws IOException {
    a=in.readLong();
    b=in.readFloat();
}
  • 比较 (正序为例)
public int compareTo(ItemBeanSer o) {
    return a>o.getA()?1:-1;
}

猜你喜欢

转载自blog.csdn.net/poppy_rain/article/details/84896447
今日推荐