r33s3n6 opened a new issue, #68720: URL: https://github.com/apache/doris/issues/68720
### 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('1.5' AS DECIMALV2(10,0))` is 2.000000000 when FE folds it and 1.500000000 when BE casts a string column. `CAST(1.5 AS DECIMALV2(10,0))` folds to 2.000000000, but the same cast of a DECIMAL(10,1) column fails in BE with `not support NonStrictMode: from Decimal(10, 1) cast to Decimal(27, 9)`. String to DECIMALV2: FE `2.000000000`, BE `1.500000000`. DECIMAL(10,1) to DECIMALV2: FE `2.000000000`, BE error. ``` SET enable_sql_cache = false SELECT CAST('1.5' AS DECIMALV2(10,0)) AS fe, CAST(s1 AS DECIMALV2(10,0)) AS be FROM t +-------------+-------------+ | fe | be | +-------------+-------------+ | 2.000000000 | 1.500000000 | +-------------+-------------+ SELECT CAST(1.5 AS DECIMALV2(10,0)) AS fe FROM t +-------------+ | fe | +-------------+ | 2.000000000 | +-------------+ SELECT CAST(dc1 AS DECIMALV2(10,0)) AS be FROM t ERROR 1105 (HY000) at line 4: errCode = 2, detailMessage = (10.30.42.3)[RUNTIME_ERROR]not support NonStrictMode: from Decimal(10, 1) cast to Decimal(27, 9) SET debug_skip_fold_constant = true SELECT CAST('1.5' AS DECIMALV2(10,0)) +--------------------------------+ | CAST('1.5' AS DECIMALV2(10,0)) | +--------------------------------+ | 1.500000000 | +--------------------------------+ ``` - **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: 2, CAST(s1[#1] AS decimalv2(10,0))` - **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 and BE give the same value for the same cast, and BE supports the cast that FE folds. ### How to Reproduce? Deployment: single FE + single BE, default session variables. ```sql CREATE TABLE t(id INT, s1 STRING, dc1 DECIMAL(10,1)) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES('replication_num' = '1'); INSERT INTO t VALUES (1, '1.5', 1.5); SET enable_sql_cache = false; SELECT CAST('1.5' AS DECIMALV2(10,0)) AS fe, CAST(s1 AS DECIMALV2(10,0)) AS be FROM t; SELECT CAST(1.5 AS DECIMALV2(10,0)) AS fe FROM t; SELECT CAST(dc1 AS DECIMALV2(10,0)) AS be FROM t; SET debug_skip_fold_constant = true; SELECT CAST('1.5' AS DECIMALV2(10,0)); ``` ### Anything Else? FE's literal cast rounds HALF_UP to the target scale; BE's string-to-DECIMALV2 cast keeps the digits. The BE specialization for DECIMALV3 to DECIMALV2 requires `IsDataTypeDecimalV3<ToDataType> && IsDataTypeDecimalV2<ToDataType>`, which can never hold, so the cast falls through to the default `CastToImpl`, which returns `not support`. - FE: [fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java#L395-L398](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java#L395-L398) — `getDecimalLiteral`: `setScale(sTarget, HALF_UP)` - BE: [be/src/exprs/function/cast/cast_to_decimal.h#L897-L900](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/cast/cast_to_decimal.h#L897-L900) — `requires(IsDataTypeDecimalV3<ToDataType> && IsDataTypeDecimalV2<ToDataType>)` 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]
