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

   Breakwater-GitHub-Analysis-Slot: slot_c18c27a29256
   
   **Triage: reproducible correctness bug by code inspection in the reported 
4.1.4 build.** The supplied SQL and `EXPLAIN` distinguish FE constant folding 
from BE evaluation. I have not run a Doris cluster independently, but the 
reported BE value follows directly from the checked 4.1.4 source 
(`ad35a140c7f`).
   
   **Verified mechanism**
   
   - For a `DOUBLE` column and constant `-25`, the BE dispatches to 
floating-point rounding and computes `scale = int_exp10(-scale_arg)` 
([`round.h`, lines 
449–480](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/be/src/exprs/function/round.h#L449-L480)).
 `int_exp10(25)` returns `UINT64_MAX`, rather than 10^25 ([`int_exp.h`, lines 
56–64](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/be/src/exec/common/int_exp.h#L56-L64)).
   - The floating-point path divides by that scale, rounds, then multiplies by 
it ([`round.h`, lines 
266–313](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/be/src/exprs/function/round.h#L266-L313)).
 In `DOUBLE`, `UINT64_MAX` converts to `1.8446744073709552e19`; `round(1e20 / 
scale) * scale` is `9.223372036854776e19`, exactly the reported BE result.
   - FE's literal overload instead converts the `DOUBLE` to a decimal and 
rounds at the requested scale ([`NumericArithmetic.java`, lines 
376–380](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java#L376-L380)),
 using decimal `HALF_UP` rounding ([`DecimalV3Literal.java`, lines 
123–131](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java#L123-L131)).
 For `1e20` at `-25`, that gives 0.
   
   **Scope and next steps**
   
   1. Handle `DOUBLE`/`FLOAT` scales beyond the integer power-of-ten helper's 
range with the requested decimal magnitude and explicit handling of 
floating-point overflow/underflow. Keep FE and BE rounding semantics aligned. 
The same BE dispatch uses `int_exp10` for positive scales above 19, so audit 
those cases too ([`round.h`, lines 
469–480](https://github.com/apache/doris/blob/ad35a140c7fd0b842f18c23300bac581f7d04326/be/src/exprs/function/round.h#L469-L480)).
   2. Add regression coverage comparing folded literals with column execution 
(or `debug_skip_fold_constant=true`) for `DOUBLE` at `-19`, `-20`, and `-25`, 
including positive and negative inputs. Include positive scales above 19 and 
inspect other rounding functions that share this dispatcher. A specific 
expected case is `round(1e20, -25) = 0` in both paths.
   
   No logs or profile are needed to establish this code-level mismatch; the 
issue already supplies the version, SQL, output, and plan distinction. A live 
4.1.4 regression run is still needed to verify the eventual fix and boundary 
behavior. No code changes were made during this triage.
   


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