public static Object extractPigObject(Object o, HCatFieldSchema hfs) throws Exception {
    /*Note that HCatRecordSerDe.serializePrimitiveField() will be called before this, thus some
    * type promotion/conversion may occur: e.g. Short to Integer.  We should refactor this so
    * that it's hapenning in one place per module/product that we are integrating with.
    * All Pig conversion should be done here, etc.*/
    if(o == null) {
      return null;
    }
    Object result;
    Type itemType = hfs.getType();
    switch (itemType) {
    case BINARY:
      result = new DataByteArray((byte[]) o);
      break;
    case STRUCT:
      result = transformToTuple((List<?>) o, hfs);
      break;
    case ARRAY:
      result = transformToBag((List<?>) o, hfs);
      break;
    case MAP:
      result = transformToPigMap((Map<?,?>) o, hfs);
      break;
    case DECIMAL:
      result = ((HiveDecimal)o).bigDecimalValue();
      break;
    case CHAR:
      result = ((HiveChar)o).getValue();
      break;
    case VARCHAR:
      result = ((HiveVarchar)o).getValue();
      break;
    case DATE:
      /*java.sql.Date is weird.  It automatically adjusts it's millis value to be in the local TZ
      * e.g. d = new java.sql.Date(System.currentMillis()).toString() so if you do this just after
      * midnight in Palo Alto, you'll get yesterday's date printed out.*/
      Date d = (Date)o;
      result = new DateTime(d.getYear(), d.getMonth(), d.getDay(), 0, 0, DateTimeZone.UTC);
      break;
    case TIMESTAMP:
      /*DATA TRUNCATION!!!
       Timestamp may have nanos; we'll strip those away and create a Joda DateTime
       object in local TZ; This is arbitrary, since Hive value doesn't have any TZ notion, but
       we need to set something for TZ.
       Timestamp is consistently in GMT (unless you call toString() on it) so we use millis*/
      result = new DateTime(((Timestamp)o).toEpochMilli(), DateTimeZone.UTC);
      break;
    default:
      result = o;
      break;
    }
    return result;
  }
Converts object from Hive's value system to Pig's value system
see HCatBaseStorer#getJavaObj() for Pig->Hive conversion 
@param o object from Hive value system
@return object in Pig value system
hcatalog/hcatalog-pig-adapter/src/main/java/org/apache/hive/hcatalog/pig/PigHCatUtil.java