private Object coerceToPigTypes ( FieldDescriptor fieldDescriptor , Object fieldValue ) { if ( fieldDescriptor . getType ( ) == FieldDescriptor . Type . ENUM && fieldValue != null ) { EnumValueDescriptor enumValueDescriptor = ( EnumValueDescriptor ) fieldValue ; return enumValueDescriptor . getName ( ) ; } else if ( fieldDescriptor . getType ( ) == FieldDescriptor . Type . BOOL && fieldValue != null ) { Boolean boolValue = ( Boolean ) fieldValue ; return new Integer ( boolValue ? 1 : 0 ) ; } else if ( fieldDescriptor . getType ( ) == FieldDescriptor . Type . BYTES && fieldValue != null ) { ByteString bsValue = ( ByteString ) fieldValue ; return new DataByteArray ( bsValue . toByteArray ( ) ) ; } return fieldValue ; }
If the given field value is an enum translate it to the enum s name as a string since Pig cannot handle enums . Also if the given field value is a bool translate it to 0 or 1 to avoid Pig bools which can be sketchy .