You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2024/01/16 12:23:31 UTC

(doris) 04/05: [fix](Nereids) remove useless substr of string like type cast (#29997)

This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git

commit e693249f5b273d331b5da3cc9500a2f09729f6e4
Author: morrySnow <10...@users.noreply.github.com>
AuthorDate: Tue Jan 16 20:16:53 2024 +0800

    [fix](Nereids) remove useless substr of string like type cast (#29997)
---
 .../java/org/apache/doris/nereids/rules/analysis/BindSink.java     | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
index 4ce7350cf2d..7dbb6b3e1e1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
@@ -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);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org