Database Reference
In-Depth Information
b2 . length ),
greaterThan ( 0 ));
Writable Classes
Hadoop comes with a large selection of Writable classes, which are available in the
org.apache.hadoop.io package. They form the class hierarchy shown in Fig-
ure 5-1 .
Writable wrappers for Java primitives
There are Writable wrappers for all the Java primitive types (see Table 5-7 ) except
char (which can be stored in an IntWritable ). All have a get() and set() meth-
od for retrieving and storing the wrapped value.
Table 5-7. Writable wrapper classes for Java primitives
Java primitive Writable implementation Serialized size (bytes)
1
boolean
BooleanWritable
1
byte
ByteWritable
2
short
ShortWritable
4
int
IntWritable
1-5
VIntWritable
4
float
FloatWritable
8
long
LongWritable
1-9
VLongWritable
8
double
DoubleWritable
When it comes to encoding integers, there is a choice between the fixed-length formats
( IntWritable and LongWritable ) and the variable-length formats ( VIntWrit-
able and VLongWritable ). The variable-length formats use only a single byte to en-
code the value if it is small enough (between -112 and 127, inclusive); otherwise, they use
the first byte to indicate whether the value is positive or negative, and how many bytes
follow. For example, 163 requires two bytes:
byte [] data = serialize ( new VIntWritable ( 163 ));
assertThat ( StringUtils . byteToHexString ( data ), is ( "8fa3" ));
Search WWH ::




Custom Search