[fix](nereids)keep cast operator if cast a varchar to another longer varchar in LogicalSetOperator (#27393)

This commit is contained in:
starocean999
2023-11-24 14:07:04 +08:00
committed by GitHub
parent dfe3a2dd01
commit dbbab63623
3 changed files with 39 additions and 2 deletions

View File

@ -144,8 +144,8 @@ public abstract class LogicalSetOperation extends AbstractLogicalPlan implements
Slot left = child(0).getOutput().get(i);
Slot right = child(1).getOutput().get(i);
DataType compatibleType = getAssignmentCompatibleType(left.getDataType(), right.getDataType());
Expression newLeft = TypeCoercionUtils.castIfNotSameType(left, compatibleType);
Expression newRight = TypeCoercionUtils.castIfNotSameType(right, compatibleType);
Expression newLeft = TypeCoercionUtils.castIfNotSameTypeStrict(left, compatibleType);
Expression newRight = TypeCoercionUtils.castIfNotSameTypeStrict(right, compatibleType);
if (newLeft instanceof Cast) {
newLeft = new Alias(newLeft, left.getName());
}

View File

@ -423,6 +423,20 @@ public class TypeCoercionUtils {
}
}
/**
* like castIfNotSameType does, but varchar or char type would be cast to target length exactly
*/
public static Expression castIfNotSameTypeStrict(Expression input, DataType targetType) {
if (input.isNullLiteral()) {
return new NullLiteral(targetType);
} else if (input.getDataType().equals(targetType) || isSubqueryAndDataTypeIsBitmap(input)) {
return input;
} else {
checkCanCastTo(input.getDataType(), targetType);
return unSafeCast(input, targetType);
}
}
private static boolean isSubqueryAndDataTypeIsBitmap(Expression input) {
return input instanceof SubqueryExpr && input.getDataType().isBitmapType();
}