// high-level type checking
if (binCond.getCondition().getType() != DataType.BOOLEAN) {
int errCode = 1047;
String msg = "Condition in BinCond must be boolean" ;
msgCollector.collect(msg, MessageType.Error);
throw new TypeCheckerException(binCond, msg, errCode, PigException.INPUT) ;
}
byte lhsType = binCond.getLhs().getType() ;
byte rhsType = binCond.getRhs().getType() ;
// If both sides are number, we can convert the smaller type to the bigger type
if (DataType.isNumberType(lhsType) && DataType.isNumberType(rhsType)) {
byte biggerType = lhsType > rhsType ? lhsType:rhsType ;
if (biggerType > lhsType) {
insertCast(binCond, biggerType, binCond.getLhs());
}
else if (biggerType > rhsType) {
insertCast(binCond, biggerType, binCond.getRhs());
}
}
else if ((lhsType == DataType.BYTEARRAY)
&& ((rhsType == DataType.CHARARRAY) || (DataType
.isNumberType(rhsType)))) {
// Cast byte array to the type on rhs
insertCast(binCond, rhsType, binCond.getLhs());
} else if ((rhsType == DataType.BYTEARRAY)
&& ((lhsType == DataType.CHARARRAY) || (DataType
.isNumberType(lhsType)))) {
// Cast byte array to the type on lhs
insertCast(binCond, lhsType, binCond.getRhs());
}
// A constant null is always bytearray - so cast it
// to rhs type
else if (binCond.getLhs() instanceof ConstantExpression
&& ((ConstantExpression) binCond.getLhs()).getValue() == null) {
try {
insertCast(binCond, binCond.getRhs().getFieldSchema(), binCond.getLhs());
} catch (FrontendException e) {
int errCode = 2216;
String msg = "Problem getting fieldSchema for " +binCond.getRhs();
throw new TypeCheckerException(binCond, msg, errCode, PigException.BUG, e);
}
} else if (binCond.getRhs() instanceof ConstantExpression
&& ((ConstantExpression) binCond.getRhs()).getValue() == null) {
try {
insertCast(binCond, binCond.getLhs().getFieldSchema(), binCond.getRhs());
} catch (FrontendException e) {
int errCode = 2216;
String msg = "Problem getting fieldSchema for " +binCond.getRhs();
throw new TypeCheckerException(binCond, msg, errCode, PigException.BUG, e);
}
} else if (lhsType == rhsType) {
// Matching schemas if we're working with tuples/bags
if (DataType.isSchemaType(lhsType)) {
try {
if(! binCond.getLhs().getFieldSchema().isEqual(binCond.getRhs().getFieldSchema())){
int errCode = 1048;
String msg = "Two inputs of BinCond must have compatible schemas."
+ " left hand side: " + binCond.getLhs().getFieldSchema()
+ " right hand side: " + binCond.getRhs().getFieldSchema();
msgCollector.collect(msg, MessageType.Error) ;
throw new TypeCheckerException(binCond, msg, errCode, PigException.INPUT) ;
}
// TODO: We may have to merge the schema here
// if the previous check is not exact match
}
catch (FrontendException fe) {
int errCode = 1049;
String msg = "Problem during evaluaton of BinCond output type" ;
msgCollector.collect(msg, MessageType.Error) ;
throw new TypeCheckerException(binCond, msg, errCode, PigException.INPUT, fe) ;
}
}
}
else {
int errCode = 1050;
String msg = "Unsupported input type for BinCond: left hand side: "
+ DataType.findTypeName(lhsType) + "; right hand side: "
+ DataType.findTypeName(rhsType);
msgCollector.collect(msg, MessageType.Error) ;
throw new TypeCheckerException(binCond, msg, errCode, PigException.INPUT) ;
}
}