yongster opened a new pull request, #10707:
URL: https://github.com/apache/arrow-rs/pull/10707

   # Which issue does this PR close?
   
   - Closes #10706.
   
   # Rationale for this change
   
   `cast` / `cast_with_options` from an integer array to `Decimal32` or
   `Decimal64` can rewrite the value instead of rejecting it.
   
   `cast_integer_to_decimal` first used `AsPrimitive` (`as`), which wraps when
   the source integer does not fit the decimal native type. The precision check
   then ran on the already-truncated value. If that wrapped value happened to
   fit the requested precision, it was stored as if it were the original number.
   
   Examples on current `main`:
   
   - `Int64(5_000_000_000) -> Decimal32(9, 0)` (`safe: true`) becomes 
`705032704`
   - `UInt32(4_000_000_000) -> Decimal32(9, 0)` (`safe: false`) becomes 
`-294967296`
   - `UInt64::MAX -> Decimal64(18, 0)` (`safe: false`) becomes `-1`
   
   The same inputs cast to `Decimal128` already return null / `Err`, because
   `i64 as i128` is lossless.
   
   # What changes are included in this PR?
   
   - Convert the source integer through a range-checked `i128` path
     (`num_cast` + `DecimalCast`) before applying scale and precision.
   - `safe: true` writes null when the original value does not fit; `safe: 
false`
     returns `Err` and reports the original value.
   - Add regression tests for `Int64 -> Decimal32`, `UInt32 -> Decimal32`, and
     `UInt64::MAX -> Decimal64`.
   
   # Are these changes tested?
   
   Yes. I ran:
   
   ```text
   cargo test -p arrow-cast --lib -- cast
   cargo clippy -p arrow-cast --all-targets --all-features -- -D warnings
   cargo +stable fmt --all -- --check


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

Reply via email to