自定义Writable

1.hadoop默认提供Writable


 

  • int -- IntWritable
  • long -- LongWritable
  • String -- Text
  • null -- NullWritable
  • double -- DoubleWritable
  • float -- FloatWritable
  • boolean -- BooleanWritable

 

2.自定义Writable


 

自定义类必须实现WritableCompare,WritableCompare 继承了Writable、Compare接口

如果自定义类型需要排序推荐实现WritableComparable接口,如果不需要排序直接实现Writable即可。

 

自定义类重载一下方法

 1 //用来排序的
 2 public int compareTo(T o){
 3 
 4 }
 5 
 6 //写得序列化
 7 void write(DataOutput out){
 8 
 9 }
10 
11 //读的序列化
12 void readFields(DataInput in){
13 
14 }
View Code

 

posted @ 2020-04-19 17:52  Q1Zhen  阅读(246)  评论(0编辑  收藏  举报