yujun777 commented on code in PR #53697:
URL: https://github.com/apache/doris/pull/53697#discussion_r2241957523


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java:
##########
@@ -167,34 +154,47 @@ protected boolean unStrictCastNullable() {
                 } else {
                     range = ((DecimalV3Type) childDataType).getRange();
                 }
-                if (range >= 39) {
+                if (range >= LargeIntType.RANGE) {
                     return true;
                 }
-                if (targetType.isTinyIntType() && range >= 3) {
+                if (targetType.isTinyIntType() && range >= TinyIntType.RANGE) {
                     return true;
                 }
-                if (targetType.isSmallIntType() && range >= 5) {
+                if (targetType.isSmallIntType() && range >= 
SmallIntType.RANGE) {
                     return true;
                 }
-                if (targetType.isIntegerType() && range >= 10) {
+                if (targetType.isIntegerType() && range >= IntegerType.RANGE) {
                     return true;
                 }
-                return targetType.isBigIntType() && range >= 19;
+                return targetType.isBigIntType() && range >= BigIntType.RANGE;
             } else if (targetType.isDecimalLikeType()) {
                 // Decimal to decimal
                 int targetRange = targetType.isDecimalV2Type() ? 
((DecimalV2Type) targetType).getRange()
                         : ((DecimalV3Type) targetType).getRange();
                 int sourceRange = childDataType.isDecimalV2Type() ? 
((DecimalV2Type) childDataType).getRange()
                         : ((DecimalV3Type) childDataType).getRange();
-                return sourceRange > targetRange;
+                if (sourceRange > targetRange) {
+                    return true;
+                }
+                if (sourceRange < targetRange) {
+                    return false;
+                }
+                // When source range == target range, if source precision is 
larger than target precision,
+                // it is possible to be null when fraction part overflow.
+                // e.g. decimal(3, 2) to decimal(2, 1), 9.99 to decimal(2, 1) 
overflow, result is null.
+                int targetPrecision = targetType.isDecimalV2Type() ? 
((DecimalV2Type) targetType).getPrecision()

Review Comment:
   9.99 to decimal(2,1),  what's result, can it be 9.9 ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to