r33s3n6 opened a new issue, #68721: URL: https://github.com/apache/doris/issues/68721
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues. ### Version 4.1.4 (doris-4.1.4-rc04-ad35a140c7f), single FE + single BE ### What's Wrong? `CAST(CAST(0.1 AS FLOAT) AS DOUBLE)` folds to 0.1 in FE, while BE widens the float exactly and returns 0.10000000149011612. Casting to DECIMAL(20,10) gives 0.1000000000 and 0.1000000015. FE folding: `0.1` and `0.1000000000`. BE: `0.10000000149011612` and `0.1000000015`. ``` SET enable_sql_cache = false SELECT CAST(CAST(0.1 AS FLOAT) AS DOUBLE) AS fe1, CAST(f1 AS DOUBLE) AS be1, CAST(CAST(0.1 AS FLOAT) AS DECIMAL(20,10)) AS fe2, CAST(f1 AS DECIMAL(20,10)) AS be2 FROM t +------+---------------------+--------------+--------------+ | fe1 | be1 | fe2 | be2 | +------+---------------------+--------------+--------------+ | 0.1 | 0.10000000149011612 | 0.1000000000 | 0.1000000015 | +------+---------------------+--------------+--------------+ SET debug_skip_fold_constant = true SELECT CAST(CAST(0.1 AS FLOAT) AS DOUBLE), CAST(CAST(0.1 AS FLOAT) AS DECIMAL(20,10)) +------------------------------------+--------------------------------------------+ | CAST(CAST(0.1 AS FLOAT) AS DOUBLE) | CAST(CAST(0.1 AS FLOAT) AS DECIMAL(20,10)) | +------------------------------------+--------------------------------------------+ | 0.10000000149011612 | 0.1000000015 | +------------------------------------+--------------------------------------------+ ``` - **FE constant folding**: all arguments are literals, so Nereids folds the call during planning. Check: EXPLAIN shows the literal in place of the call: `final projections: 0.1, CAST(f1[#1] AS double)` - **BE execution**: the arguments are columns (or `SET debug_skip_fold_constant = true`), so BE computes the call. Check: EXPLAIN keeps the call. ### What You Expected? FE folding and BE give the same value. ### How to Reproduce? Deployment: single FE + single BE, default session variables. ```sql CREATE TABLE t(id INT, f1 FLOAT) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES('replication_num' = '1'); INSERT INTO t VALUES (1, 0.1); SET enable_sql_cache = false; SELECT CAST(CAST(0.1 AS FLOAT) AS DOUBLE) AS fe1, CAST(f1 AS DOUBLE) AS be1, CAST(CAST(0.1 AS FLOAT) AS DECIMAL(20,10)) AS fe2, CAST(f1 AS DECIMAL(20,10)) AS be2 FROM t; SET debug_skip_fold_constant = true; SELECT CAST(CAST(0.1 AS FLOAT) AS DOUBLE), CAST(CAST(0.1 AS FLOAT) AS DECIMAL(20,10)); ``` ### Anything Else? FE's `FloatLiteral` casts with `Double.parseDouble(String.valueOf(value))` and `new BigDecimal(Float.toString(value))`, i.e. through the shortest decimal string of the float; BE converts the binary value. - FE: [fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FloatLiteral.java#L70-L87](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FloatLiteral.java#L70-L87) — `uncheckedCastTo`: through `String.valueOf` / `Float.toString` - BE: [be/src/exprs/function/cast/cast_to_float.h#L29-L39](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/cast/cast_to_float.h#L29-L39) — number to float: `static_cast_no_overflow` Found with AI assistance. ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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]
