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

   Thanks for the detailed reproducer. **Initial assessment: confirmed 
code-path inconsistency in 4.1.4** (the reported SQL output itself has not been 
independently run here). The issue currently has no labels.
   
   **Verified in the 4.1.4 source (tag resolves to the reported `ad35a140c7f` 
commit):**
   
   - Nereids literal casts call `getDecimalLiteral`, which rounds to the 
requested scale with `HALF_UP`. This explains the reported folded `2.000000000` 
for a target scale of 0. [FE literal 
conversion](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)
   - The BE string-to-decimal cast goes through 
`DataTypeDecimalSerDe::from_string_batch` and `CastToDecimal::from_string`. Its 
DECIMALV2 branch passes the fixed `DecimalV2Value::PRECISION` and `SCALE` (27, 
9) to the parser, instead of the target precision/scale arguments. Thus `1.5` 
is parsed at internal scale 9, consistent with the reported BE result, even 
when the SQL target is `DECIMALV2(10,0)`. [BE string 
cast](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/cast/cast_to_decimal.h#L38-L49)
 · [batch 
path](https://github.com/apache/doris/blob/4.1.4/be/src/core/data_type_serde/data_type_decimal_serde.cpp#L539-L564)
   - The apparent DECIMALV3-to-DECIMALV2 specialization requires its 
*destination* type to be both DecimalV3 and DecimalV2, so it cannot match. The 
generic fallback returns the exact `not support  NonStrictMode` wording in the 
report. Also, the specialization body itself returns an unsupported error: 
changing only its `requires` clause would not implement the cast. [BE 
specialization](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/cast/cast_to_decimal.h#L897-L910)
 · 
[fallback](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/cast/cast_base.h#L186-L197)
   
   **Suggested next steps:** Treat this as a query correctness/cast coverage 
bug. Align BE string-to-DECIMALV2 conversion with the declared target scale 
while retaining its internal 9-digit representation; implement the 
DECIMALV3-to-DECIMALV2 conversion with the intended rounding, 
precision/overflow, and strict/non-strict behavior. Add regression coverage 
comparing folded literals, `debug_skip_fold_constant=true`, and column casts 
for both source types, including scale 0, other scales, positive/negative 
halfway values, and overflow boundaries.
   
   The supplied version, schema, SQL, result, and error are sufficient for 
initial triage; no logs or profile are needed to locate these code paths. A 
live 4.1.4 regression run is still needed to verify the full behavior and any 
proposed fix.
   
   Breakwater-GitHub-Analysis-Slot: slot_47abc362812b
   


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