r33s3n6 opened a new issue, #68722: URL: https://github.com/apache/doris/issues/68722
### 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(1e38 AS DOUBLE) AS LARGEINT)` folds to 100000000000000000000000000000000000000 in FE and is 99999999999999997748809823456034029568 (the exact value of the double) in BE. FE folding: `100000000000000000000000000000000000000`. BE: `99999999999999997748809823456034029568`. ``` SET enable_sql_cache = false SELECT CAST(CAST(1e38 AS DOUBLE) AS LARGEINT) AS fe, CAST(d1 AS LARGEINT) AS be FROM t +-----------------------------------------+----------------------------------------+ | fe | be | +-----------------------------------------+----------------------------------------+ | 100000000000000000000000000000000000000 | 99999999999999997748809823456034029568 | +-----------------------------------------+----------------------------------------+ SET debug_skip_fold_constant = true SELECT CAST(CAST(1e38 AS DOUBLE) AS LARGEINT) +----------------------------------------+ | CAST(CAST(1e38 AS DOUBLE) AS LARGEINT) | +----------------------------------------+ | 99999999999999997748809823456034029568 | +----------------------------------------+ ``` - **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: 100000000000000000000000000000000000000, CAST(d1[#1] AS largeint)` - **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, d1 DOUBLE) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES('replication_num' = '1'); INSERT INTO t VALUES (1, 1e38); SET enable_sql_cache = false; SELECT CAST(CAST(1e38 AS DOUBLE) AS LARGEINT) AS fe, CAST(d1 AS LARGEINT) AS be FROM t; SET debug_skip_fold_constant = true; SELECT CAST(CAST(1e38 AS DOUBLE) AS LARGEINT); ``` ### Anything Else? FE's `FractionalLiteral` builds `new BigDecimal(value.toString())` from the shortest decimal string; BE truncates the binary value. - FE: [fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FractionalLiteral.java#L56-L60](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FractionalLiteral.java#L56-L60) — `new BigDecimal(value.toString())` - BE: [be/src/exprs/function/cast/cast_to_int.h#L87-L88](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/cast/cast_to_int.h#L87-L88) — float source: `CastToInt::from_float` 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]
