in pig/src/main/java/com/twitter/elephantbird/pig/util/PigToThrift.java [118:151]
public static Object toThriftValue(Field thriftField, Object pigValue) {
try {
switch (thriftField.getType()) {
case TType.BOOL:
return Boolean.valueOf(((Integer)pigValue) != 0);
case TType.BYTE :
return ((Integer)pigValue).byteValue();
case TType.I16 :
return Short.valueOf(((Integer)pigValue).shortValue());
case TType.STRING:
return toStringType(pigValue);
case TType.STRUCT:
return toThrift(thriftField.gettStructDescriptor(), (Tuple)pigValue);
case TType.MAP:
return toThriftMap(thriftField, (Map<String, Object>)pigValue);
case TType.SET:
return toThriftSet(thriftField.getSetElemField(), (DataBag) pigValue);
case TType.LIST:
return toThriftList(thriftField.getListElemField(), (DataBag)pigValue);
case TType.ENUM:
return toThriftEnum(thriftField, (String) pigValue);
default:
// standard types : I32, I64, DOUBLE, etc.
return pigValue;
}
} catch (Exception e) {
// mostly a schema mismatch.
LOG.warn(String.format(
"Failed to set field '%s' of type '%s' with value '%s' of type '%s'",
thriftField.getName(), ThriftUtils.getFieldValueType(thriftField).getName(),
pigValue, pigValue.getClass().getName()), e);
}
return null;
}