in src/org/apache/pig/impl/logicalLayer/schema/Schema.java [216:280]
public static boolean castable(
Schema.FieldSchema castFs,
Schema.FieldSchema inputFs) {
if(castFs == null && inputFs == null) {
return false;
}
if (castFs == null) {
return false ;
}
if (inputFs == null) {
return false ;
}
byte inputType = inputFs.type;
byte castType = castFs.type;
if (DataType.isSchemaType(castFs.type)) {
if(inputType == DataType.BYTEARRAY) {
// good
} else if (inputType == castType) {
// Don't do the comparison if both embedded schemas are
// null. That will cause Schema.equals to return false,
// even though we want to view that as true.
if (!(castFs.schema == null && inputFs.schema == null)) {
// compare recursively using schema
if (!Schema.castable(castFs.schema, inputFs.schema)) {
return false ;
}
}
} else {
return false;
}
} else {
if (inputType == castType) {
// good
}
else if (inputType == DataType.BOOLEAN && (castType == DataType.CHARARRAY
|| castType == DataType.BYTEARRAY || DataType.isNumberType(castType))) {
// good
}
else if (DataType.isNumberType(inputType) && (castType == DataType.CHARARRAY
|| castType == DataType.BYTEARRAY || DataType.isNumberType(castType)
|| castType == DataType.BOOLEAN || castType == DataType.DATETIME)) {
// good
}
else if (inputType == DataType.DATETIME && (castType == DataType.CHARARRAY
|| castType == DataType.BYTEARRAY || DataType.isNumberType(castType))) {
// good
}
else if (inputType == DataType.CHARARRAY && (castType == DataType.BYTEARRAY
|| DataType.isNumberType(castType) || castType == DataType.BOOLEAN
|| castType == DataType.DATETIME)) {
// good
}
else if (inputType == DataType.BYTEARRAY) {
// good
}
else {
return false;
}
}
return true ;
}