[fix](Nereids) remove useless substr of string like type cast (#29997)
This commit is contained in:
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user