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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 9ad08a42a42 [opt](Nereids) remove decimalv2 signature from Nvl and 
CaseWhen (#29221)
9ad08a42a42 is described below

commit 9ad08a42a42ed123ebf483fd7f8067fd93c3e206
Author: morrySnow <[email protected]>
AuthorDate: Thu Dec 28 21:24:52 2023 +0800

    [opt](Nereids) remove decimalv2 signature from Nvl and CaseWhen (#29221)
---
 .../nereids/trees/expressions/functions/scalar/Nvl.java    |  7 ++-----
 .../org/apache/doris/nereids/util/TypeCoercionUtils.java   | 14 ++++++++------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Nvl.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Nvl.java
index 9b8e51d238d..2bf82e27476 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Nvl.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Nvl.java
@@ -29,7 +29,6 @@ import org.apache.doris.nereids.types.DateTimeType;
 import org.apache.doris.nereids.types.DateTimeV2Type;
 import org.apache.doris.nereids.types.DateType;
 import org.apache.doris.nereids.types.DateV2Type;
-import org.apache.doris.nereids.types.DecimalV2Type;
 import org.apache.doris.nereids.types.DecimalV3Type;
 import org.apache.doris.nereids.types.DoubleType;
 import org.apache.doris.nereids.types.FloatType;
@@ -58,6 +57,8 @@ public class Nvl extends ScalarFunction
             
FunctionSignature.ret(IntegerType.INSTANCE).args(IntegerType.INSTANCE, 
IntegerType.INSTANCE),
             
FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE, 
BigIntType.INSTANCE),
             
FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE, 
LargeIntType.INSTANCE),
+            FunctionSignature.ret(DecimalV3Type.WILDCARD)
+                    .args(DecimalV3Type.WILDCARD, DecimalV3Type.WILDCARD),
             
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, 
DoubleType.INSTANCE),
             FunctionSignature.ret(FloatType.INSTANCE).args(FloatType.INSTANCE, 
FloatType.INSTANCE),
             FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE, 
DateType.INSTANCE),
@@ -66,10 +67,6 @@ public class Nvl extends ScalarFunction
                     .args(DateTimeV2Type.SYSTEM_DEFAULT, 
DateTimeV2Type.SYSTEM_DEFAULT),
             FunctionSignature.ret(DateV2Type.INSTANCE)
                     .args(DateV2Type.INSTANCE, DateV2Type.INSTANCE),
-            FunctionSignature.ret(DecimalV3Type.WILDCARD)
-                    .args(DecimalV3Type.WILDCARD, DecimalV3Type.WILDCARD),
-            FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT)
-                    .args(DecimalV2Type.SYSTEM_DEFAULT, 
DecimalV2Type.SYSTEM_DEFAULT),
             
FunctionSignature.ret(BitmapType.INSTANCE).args(BitmapType.INSTANCE, 
BitmapType.INSTANCE),
             FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
                     .args(VarcharType.SYSTEM_DEFAULT, 
VarcharType.SYSTEM_DEFAULT),
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
index 9bca4b43bb4..23608691ad1 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
@@ -748,25 +748,27 @@ public class TypeCoercionUtils {
         Optional<DataType> optionalCommonType = 
TypeCoercionUtils.findWiderCommonTypeForCaseWhen(dataTypesForCoercion);
         return optionalCommonType
                 .map(commonType -> {
+                    DataType realCommonType = commonType instanceof 
DecimalV2Type
+                            ? DecimalV3Type.forType(commonType) : commonType;
                     List<Expression> newChildren
                             = caseWhen.getWhenClauses().stream()
                             .map(wc -> {
                                 Expression valueExpr = 
TypeCoercionUtils.castIfNotSameType(
-                                        wc.getResult(), commonType);
+                                        wc.getResult(), realCommonType);
                                 // we must cast every child to the common 
type, and then
                                 // FoldConstantRuleOnFe can eliminate some 
branches and direct
                                 // return a branch value
-                                if 
(!valueExpr.getDataType().equals(commonType)) {
-                                    valueExpr = new Cast(valueExpr, 
commonType);
+                                if 
(!valueExpr.getDataType().equals(realCommonType)) {
+                                    valueExpr = new Cast(valueExpr, 
realCommonType);
                                 }
                                 return wc.withChildren(wc.getOperand(), 
valueExpr);
                             })
                             .collect(Collectors.toList());
                     caseWhen.getDefaultValue()
                             .map(dv -> {
-                                Expression defaultExpr = 
TypeCoercionUtils.castIfNotSameType(dv, commonType);
-                                if 
(!defaultExpr.getDataType().equals(commonType)) {
-                                    defaultExpr = new Cast(defaultExpr, 
commonType);
+                                Expression defaultExpr = 
TypeCoercionUtils.castIfNotSameType(dv, realCommonType);
+                                if 
(!defaultExpr.getDataType().equals(realCommonType)) {
+                                    defaultExpr = new Cast(defaultExpr, 
realCommonType);
                                 }
                                 return defaultExpr;
                             })


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to