public static int compare(Object o1, Object o2, byte dt1, byte dt2) {
    if (dt1 == dt2) {
      switch (dt1) {
      case NULL:
        return 0;

      case BOOLEAN:
        return ((Boolean) o1).compareTo((Boolean) o2);

      case BYTE:
        return ((Byte) o1).compareTo((Byte) o2);

      case INTEGER:
        return ((Integer) o1).compareTo((Integer) o2);

      case LONG:
        return ((Long) o1).compareTo((Long) o2);

      case FLOAT:
        return ((Float) o1).compareTo((Float) o2);

      case DOUBLE:
        return ((Double) o1).compareTo((Double) o2);

      case STRING:
        return ((String) o1).compareTo((String) o2);

      case SHORT:
        return ((Short) o1).compareTo((Short) o2);

      case BINARY:
        return compareByteArray((byte[]) o1, (byte[]) o2);

      case LIST:
        List<?> l1 = (List<?>) o1;
        List<?> l2 = (List<?>) o2;
        int len = l1.size();
        if (len != l2.size()) {
          return len - l2.size();
        } else {
          for (int i = 0; i < len; i++) {
            int cmpVal = compare(l1.get(i), l2.get(i));
            if (cmpVal != 0) {
              return cmpVal;
            }
          }
          return 0;
        }

      case MAP: {
        Map<?, ?> m1 = (Map<?, ?>) o1;
        Map<?, ?> m2 = (Map<?, ?>) o2;
        int sz1 = m1.size();
        int sz2 = m2.size();
        if (sz1 < sz2) {
          return -1;
        } else if (sz1 > sz2) {
          return 1;
        } else {
          // This is bad, but we have to sort the keys of the maps in order
          // to be commutative.
          TreeMap<Object, Object> tm1 = new TreeMap<Object, Object>(m1);
          TreeMap<Object, Object> tm2 = new TreeMap<Object, Object>(m2);
          Iterator<Entry<Object, Object>> i1 = tm1.entrySet().iterator();
          Iterator<Entry<Object, Object>> i2 = tm2.entrySet().iterator();
          while (i1.hasNext()) {
            Map.Entry<Object, Object> entry1 = i1.next();
            Map.Entry<Object, Object> entry2 = i2.next();
            int c = compare(entry1.getValue(), entry2.getValue());
            if (c != 0) {
              return c;
            } else {
              c = compare(entry1.getValue(), entry2.getValue());
              if (c != 0) {
                return c;
              }
            }
          }
          return 0;
        }
      }
      case CHAR:
        return ((HiveChar)o1).compareTo((HiveChar)o2);  
      case VARCHAR:
        return ((HiveVarchar)o1).compareTo((HiveVarchar)o2);
      case DECIMAL:
        return ((HiveDecimal)o1).compareTo((HiveDecimal)o2);
      case DATE:
        return ((Date)o1).compareTo((Date)o2);
      case TIMESTAMP:
        return ((Timestamp)o1).compareTo((Timestamp)o2);
     default:
        throw new RuntimeException("Unkown type " + dt1 +
          " in compare");
      }
    } else {
      return dt1 < dt2 ? -1 : 1;
    }
  }
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