[fix](nereids)keep cast operator if cast a varchar to another longer varchar in LogicalSetOperator (#27393)
This commit is contained in:
@ -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());
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user