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

morrysnow 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 ce02fca71e8 [fix](nereids) set operation's result type is wrong if 
decimal overflows (#27872)
ce02fca71e8 is described below

commit ce02fca71e85cb70d82dbe5056ea26271ee78559
Author: starocean999 <[email protected]>
AuthorDate: Fri Dec 1 20:05:21 2023 +0800

    [fix](nereids) set operation's result type is wrong if decimal overflows 
(#27872)
    
    pick from master #27870
---
 .../trees/plans/logical/LogicalSetOperation.java   | 32 +++++++++++++++++++---
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSetOperation.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSetOperation.java
index c58b0aa0688..1835363bce8 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSetOperation.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSetOperation.java
@@ -17,6 +17,7 @@
 
 package org.apache.doris.nereids.trees.plans.logical;
 
+import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.catalog.Type;
 import org.apache.doris.nereids.memo.GroupExpression;
 import org.apache.doris.nereids.properties.LogicalProperties;
@@ -137,10 +138,7 @@ public abstract class LogicalSetOperation extends 
AbstractLogicalPlan implements
         for (int i = 0; i < child(0).getOutput().size(); ++i) {
             Slot left = child(0).getOutput().get(i);
             Slot right = child(1).getOutput().get(i);
-            DataType compatibleType = 
DataType.fromCatalogType(Type.getAssignmentCompatibleType(
-                    left.getDataType().toCatalogDataType(),
-                    right.getDataType().toCatalogDataType(),
-                    false));
+            DataType compatibleType = 
getAssignmentCompatibleType(left.getDataType(), right.getDataType());
             Expression newLeft = TypeCoercionUtils.castIfNotSameType(left, 
compatibleType);
             Expression newRight = TypeCoercionUtils.castIfNotSameType(right, 
compatibleType);
             if (newLeft instanceof Cast) {
@@ -211,4 +209,30 @@ public abstract class LogicalSetOperation extends 
AbstractLogicalPlan implements
     public int getArity() {
         return children.size();
     }
+
+    private DataType getAssignmentCompatibleType(DataType left, DataType 
right) {
+        if (left.isNullType()) {
+            return right;
+        }
+        if (right.isNullType()) {
+            return left;
+        }
+        if (left.equals(right)) {
+            return left;
+        }
+        Type resultType = 
Type.getAssignmentCompatibleType(left.toCatalogDataType(),
+                right.toCatalogDataType(), false);
+        if (resultType.isDecimalV3()) {
+            int oldPrecision = resultType.getPrecision();
+            int oldScale = resultType.getDecimalDigits();
+            int integerPart = oldPrecision - oldScale;
+            int maxPrecision = ScalarType.MAX_DECIMAL128_PRECISION;
+            if (oldPrecision > maxPrecision) {
+                int newScale = maxPrecision - integerPart;
+                resultType =
+                        ScalarType.createDecimalType(maxPrecision, newScale < 
0 ? 0 : newScale);
+            }
+        }
+        return DataType.fromCatalogType(resultType);
+    }
 }


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

Reply via email to