private static int compareByteArray(byte[] o1, byte[] o2) {

    for (int i = 0; i < o1.length; i++) {
      if (i == o2.length) {
        return 1;
      }
      if (o1[i] == o2[i]) {
        continue;
      }
      if (o1[i] > o2[i]) {
        return 1;
      } else {
        return -1;
      }
    }

    //bytes in o1 are same as o2
    //in case o2 was longer
    if (o2.length > o1.length) {
      return -1;
    }
    return 0; //equals
  }
Determine the datatype of an object.
@param o Object to test.
@return byte code of the type, or ERROR if we don't know.
hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/DataType.java