byte outType = cast.getType();
if(outType == DataType.BYTEARRAY){
int errCode = 1051;
String msg = "Cannot cast to bytearray";
msgCollector.collect(msg, MessageType.Error) ;
throw new TypeCheckerException(cast, msg, errCode, PigException.INPUT) ;
}
LogicalFieldSchema inFs = cast.getExpression().getFieldSchema();
LogicalFieldSchema outFs = cast.getFieldSchema();
if(inFs == null){
//replace null schema with bytearray schema.
inFs = new LogicalFieldSchema(null, null, DataType.BYTEARRAY);
}
//check if the field schemas are castable
boolean castable = LogicalFieldSchema.castable(inFs, outFs);
if(!castable) {
int errCode = 1052;
String msg = "Cannot cast "
+ DataType.findTypeName(inType)
+ ((DataType.isSchemaType(inType))? " with schema " + inFs.toString(false) : "")
+ " to "
+ DataType.findTypeName(outType)
+ ((DataType.isSchemaType(outType))? " with schema " + outFs.toString(false) : "");
msgCollector.collect(msg, MessageType.Error) ;
throw new TypeCheckerException(cast, msg, errCode, PigException.INPUT) ;
}
}