}
assert keyExprsBuild.length == keyExprsProbe.length;
for (int i = 0; i < keyExprsBuild.length; i++) {
MinorType buildType = keyExprsBuild[i].getMajorType().getMinorType();
MinorType probeType = keyExprsProbe[i].getMajorType().getMinorType();
if (buildType != probeType) {
// We need to add a cast to one of the expressions
List<MinorType> types = new LinkedList<>();
types.add(buildType);
types.add(probeType);
MinorType result = TypeCastRules.getLeastRestrictiveType(types);
// Add the cast
List<LogicalExpression> args = new LinkedList<>();
if (result == null) {
throw new DrillRuntimeException(String.format("Join conditions cannot be compared failing build expression: %s failing probe expression: %s",
keyExprsBuild[i].getMajorType().toString(), keyExprsProbe[i].getMajorType().toString()));
}
else if (result != buildType) {
// Add a cast expression on top of the build expression
args.add(keyExprsBuild[i]);
FunctionCall castCall = new FunctionCall("cast" + result.toString().toUpperCase(), args, ExpressionPosition.UNKNOWN);
keyExprsBuild[i] = ExpressionTreeMaterializer.materialize(castCall, incomingBuild, new ErrorCollectorImpl(), context.getFunctionRegistry());
} else if (result != probeType) {
args.add(keyExprsProbe[i]);
FunctionCall castCall = new FunctionCall("cast" + result.toString().toUpperCase(), args, ExpressionPosition.UNKNOWN);
keyExprsProbe[i] = ExpressionTreeMaterializer.materialize(castCall, incomingProbe, new ErrorCollectorImpl(), context.getFunctionRegistry());
}
}
}
}