github-actions[bot] commented on code in PR #68733:
URL: https://github.com/apache/doris/pull/68733#discussion_r4226508920


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FractionalLiteral.java:
##########
@@ -53,7 +53,11 @@ protected Expression uncheckedCastTo(DataType targetType) 
throws AnalysisExcepti
             if (!isFinite) {
                 throw new CastException(String.format("%s can't cast to %s in 
strict mode.", getValue(), targetType));
             }
-            BigDecimal decimal = new BigDecimal(value.toString());
+            // BE converts the binary value, not the shortest decimal 
representation of
+            // the float/double, so a magnitude such as 1e38 must keep the 
double's exact value
+            BigDecimal decimal = value instanceof Double || value instanceof 
Float

Review Comment:
   [P2] Use the binary value for the checked integral overflow path too. 
`FoldConstantRuleOnFE.visitCast` calls `checkedCastTo`, which runs 
`Literal.numericOverflow(getStringValue(), targetType)` before this exact 
conversion. For `DOUBLE -2^63` to BIGINT, the display decimal is 
`-9.223372036854776E18` (below BIGINT min), so FE throws or folds NULL, while 
the binary double is exactly `-9223372036854775808` and BE accepts it. `FLOAT 
-2^31` to INT has the same issue. Make the precheck use the same exact value, 
or let this branch own the integral range check, and test the checked folding 
path.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FractionalLiteral.java:
##########
@@ -53,7 +53,11 @@ protected Expression uncheckedCastTo(DataType targetType) 
throws AnalysisExcepti
             if (!isFinite) {
                 throw new CastException(String.format("%s can't cast to %s in 
strict mode.", getValue(), targetType));
             }
-            BigDecimal decimal = new BigDecimal(value.toString());
+            // BE converts the binary value, not the shortest decimal 
representation of
+            // the float/double, so a magnitude such as 1e38 must keep the 
double's exact value
+            BigDecimal decimal = value instanceof Double || value instanceof 
Float
+                    ? new BigDecimal(((Number) value).doubleValue())

Review Comment:
   [P2] Preserve the binary FLOAT value through a DOUBLE intermediate. This 
branch makes direct `FLOAT 1e20f` to LARGEINT fold to `100000002004087734272`, 
but `FloatLiteral.uncheckedCastTo(DoubleType)` still parses 
`Float.toString(value)` (`1.0E20`), so `FLOAT -> DOUBLE -> LARGEINT` folds to 
`100000000000000000000`; BE's FLOAT-to-DOUBLE cast widens the binary float 
exactly. At FLOAT `2^127`, the nested FE fold even accepts a LARGEINT that BE 
rejects. Widen the float directly in that parallel FE path and cover both cast 
shapes.



-- 
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