Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
Hadoop >> mail # user >> WritableComparable


Copy link to this message
-
Re: WritableComparable
On Sun, Aug 14, 2011 at 10:25 PM, Joey Echeverria <[EMAIL PROTECTED]> wrote:

> What are the types of key1 and key2? What does the readFields() method
> look like?
The type of key1 is essentially a wrapper for java.util.UUID.
Here is its readFields:

public void readFields(DataInput in) throws IOException {
  id = new UUID(in.readLong(), in.readLong());
}

So, it reconstitutes the UUID by deserializing two longs.  The 'compareTo'
method of this key type delegates to java.util.UUID.compareTo.

The type of key2 wraps a different id, one that fits into a long.  In
addition to an id, it also stores an enum which designates the "source" of
this id.
Here is its readFields:

public void readFields(DataInput in) throws IOException {
  source = Source.values()[in.readByte() & 0xFF];
  id = in.readLong();
}

The source is an enum value which is serialized by writing its ordinal.
 (There are only two possible enum values, hence only one byte.)
The 'compareTo' method of this key type orders by the source values if the
id values are different, otherwise by the id values.
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB