Hadoop 中,并没有使用Java自带的基本类型类(Integer、Float等),而是使用自己开发的类。Hadoop 自带有很多序列化类型,大致分为以下两种:
1、实现了WritableComparable接口的类
基础:BooleanWritable | ByteWritable
数字:IntWritable | VIntWritable | FloatWritable | LongWritable | VLongWritable | DoubleWritable
高级:NullWritable | Text | BytesWritable | MDSHash | ObjectWritable | GenericWritable
2、仅实现了Writable接口的类
数组:ArrayWritable | TwoDArrayWritable
映射:AbstractMapWritable | MapWritable | SortedMapWritable
为便于理解 Hadoop 自带的 Writable 类型,我们使用以下表格展示 Java 基本类型和 Writable 的对应关系
Java 基本类型 |
Writable 实现 |
字节 |
boolean |
BooleanWritable |
1 |
byte |
ByteWritable |
1 |
int |
IntWritable |
4 |
float |
FloatWritable |
4 |
long |
LongWritable |
8 |
double |
DoubleWritable |
8 |
Text text = new Text("hadoop");//构造一个Text对象
text.set("autoNavi");//重新赋值