Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Hadoop >> mail # user >> Re: Serialized comparator vs normal comparator

Copy link to this message
Re: Serialized comparator vs normal comparator

Just wondering what is the difference between serialized comparator vs normal comparator given below,
the reason i am trying to understand this is how will you verify if you r using serialized comparator during debugging if the comparator is 
working or not as when you debug in eclipse it shows byte info which cannot be understood by developers.

Here r the methods i am referring to:

/** A Comparator that compares serialized IntPair. */ 
    public static class Comparator extends WritableComparator {
      public Comparator() {

     public int compare(byte[] b1, int s1, int l1,
                         byte[] b2, int s2, int l2) {
        return compareBytes(b1, s1, l1, b2, s2, l2);

    static {                                        // register this comparator
      WritableComparator.define(IntPair.class, new Comparator());

   public int compareTo(IntPair o) {
      if (first != o.first) {
        return first < o.first ? -1 : 1;
      } else if (second != o.second) {
        return second < o.second ? -1 : 1;
      } else {
        return 0;