Database Reference
In-Depth Information
public class TextArrayWritable extends ArrayWritable {
public TextArrayWritable () {
super ( Text . class );
}
}
ArrayWritable and TwoDArrayWritable both have get() and set() methods,
as well as a toArray() method, which creates a shallow copy of the array (or 2D ar-
ray).
ArrayPrimitiveWritable is a wrapper for arrays of Java primitives. The compon-
ent type is detected when you call set() , so there is no need to subclass to set the type.
MapWritable is an implementation of java.util.Map<Writable, Writ-
able> , and SortedMapWritable is an implementation of
java.util.SortedMap<WritableComparable, Writable> . The type of
each key and value field is a part of the serialization format for that field. The type is
stored as a single byte that acts as an index into an array of types. The array is populated
with the standard types in the org.apache.hadoop.io package, but custom Writ-
able types are accommodated, too, by writing a header that encodes the type array for
nonstandard types. As they are implemented, MapWritable and SortedMapWrit-
able use positive byte values for custom types, so a maximum of 127 distinct non-
standard Writable classes can be used in any particular MapWritable or Sor-
tedMapWritable instance. Here's a demonstration of using a MapWritable with
different types for keys and values:
MapWritable src = new MapWritable ();
src . put ( new IntWritable ( 1 ), new Text ( "cat" ));
src . put ( new VIntWritable ( 2 ), new LongWritable ( 163 ));
MapWritable dest = new MapWritable ();
WritableUtils . cloneInto ( dest , src );
assertThat (( Text ) dest . get ( new IntWritable ( 1 )), is ( new
Text ( "cat" )));
assertThat (( LongWritable ) dest . get ( new VIntWritable ( 2 )),
is ( new LongWritable ( 163 )));
Conspicuous by their absence are Writable collection implementations for sets and
lists. A general set can be emulated by using a MapWritable (or a SortedMapWrit-
able for a sorted set) with NullWritable values. There is also EnumSetWritable
for sets of enum types. For lists of a single type of Writable , ArrayWritable is ad-
equate, but to store different types of Writable in a single list, you can use Gener-
Search WWH ::




Custom Search