Doris-Breakwater commented on issue #68721:
URL: https://github.com/apache/doris/issues/68721#issuecomment-5978378533

   Breakwater-GitHub-Analysis-Slot: slot_a303dd8d388c
   
   **Initial assessment:** This is a well-substantiated FE/BE cast 
inconsistency in the reported 4.1.4 build, with a concrete FE cause visible in 
the matching `4.1.4` source tag (`ad35a140c7f`). The issue is currently 
unlabeled. The supplied SQL and `debug_skip_fold_constant` comparison are 
sufficient for initial triage; a query profile or logs are not needed to 
establish this value mismatch.
   
   **Verified from source:** Nereids [folds `Cast` by calling the literal's 
`checkedCastTo`](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java#L499-L532).
 For a `FloatLiteral`, [FLOAT → DOUBLE parses `String.valueOf(value)`, and 
FLOAT → DECIMAL builds `BigDecimal` from 
`Float.toString(value)`](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FloatLiteral.java#L65-L88).
 Both convert the binary32 value through its short decimal representation 
(`0.1` here). FE then [rounds the decimal to the target 
scale](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java#L385-L400).
   
   BE [widens FLOAT to DOUBLE with a numeric 
cast](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/cast/cast_to_basic_number_common.h#L324-L328);
 its [FLOAT → DECIMAL path scales the numeric value and rounds 
it](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/cast/cast_to_decimal.h#L236-L261).
 Binary32 `0.1` has the widened value `0.10000000149011612`, which rounds to 
`0.1000000015` at scale 10. This explains both pairs of results in the report. 
I confirmed the source paths and arithmetic locally, but did not run a Doris 
cluster.
   
   **Next step for maintainers:** Align FE literal casts with the BE's numeric 
conversion semantics, then add regression coverage comparing folded literals 
with column casts and with folding disabled for FLOAT → DOUBLE and FLOAT → 
DECIMAL. Include positive/negative values, scale-rounding boundaries, and 
overflow/non-finite handling so the two paths agree beyond this example. The 
exact FE implementation should be checked against BE's rounding behavior at 
boundary cases.
   


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