[fix](Nereids) remove useless substr of string like type cast (#29997)

This commit is contained in:
morrySnow
2024-01-16 20:16:53 +08:00
committed by yiguolei
parent f7a340a2df
commit e693249f5b

View File

@ -297,10 +297,13 @@ public class BindSink implements AnalysisRuleFactory {
DataType inputType = expr.getDataType();
DataType targetType = DataType.fromCatalogType(table.getFullSchema().get(i).getType());
Expression castExpr = expr;
if (isSourceAndTargetStringLikeType(inputType, targetType)) {
// TODO move string like type logic into TypeCoercionUtils#castIfNotSameType
if (isSourceAndTargetStringLikeType(inputType, targetType) && !inputType.equals(targetType)) {
int sourceLength = ((CharacterType) inputType).getLen();
int targetLength = ((CharacterType) targetType).getLen();
if (sourceLength >= targetLength && targetLength >= 0) {
if (sourceLength == targetLength) {
castExpr = TypeCoercionUtils.castIfNotSameType(castExpr, targetType);
} else if (sourceLength > targetLength && targetLength >= 0) {
castExpr = new Substring(castExpr, Literal.of(1), Literal.of(targetLength));
} else if (targetType.isStringType()) {
castExpr = new Cast(castExpr, StringType.INSTANCE);