SAY-5 opened a new pull request, #10162:
URL: https://github.com/apache/arrow-rs/pull/10162

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax.
   -->
   
   - Part of #10131.
   
   # Rationale for this change
   
   <!--
   Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.
   -->
   
   Two temporal cast paths ignore the cast safety option:
   
   - `Time32(Second)` to `Time32(Millisecond)` multiplies an `i32` by 1000 with 
`unary`, so a large value panics with "attempt to multiply with overflow" in 
debug and wraps in release.
   - `Date64` to `Date32` divides by `MILLISECONDS_IN_DAY` and then does an 
unchecked `as i32`, which silently truncates day counts that do not fit in 
`i32` (e.g. `i64::MAX` produces `-622191233`).
   
   Both are reachable from `cast`/`cast_with_options` on valid input and do not 
honour `CastOptions::safe`.
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   Both casts now follow the same pattern already used elsewhere in this file 
(for decimal and timestamp casts): in safe mode out-of-range values become null 
via `unary_opt` with a checked operation, and in non-safe mode they return a 
`CastError`/`ArithmeticOverflow` via `try_unary`.
   
   This covers the two cases shown in the issue. Other temporal casts that 
multiply into `i64` (e.g. `Time32(Second)` to `Time64`) cannot overflow for 
in-range inputs and are left unchanged.
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   
   If this PR claims a performance improvement, please include evidence such as 
benchmark results.
   -->
   
   Yes. Added `test_cast_date64_to_date32_overflow` and 
`test_cast_time32_second_to_time32_millisecond_overflow`, each checking that 
the safe cast nulls the out-of-range value and the non-safe cast errors instead 
of panicking or truncating. The existing temporal cast tests still pass.
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   
   If there are any breaking changes to public APIs, please call them out.
   -->
   
   These two casts no longer panic or silently truncate on overflow. Safe casts 
now yield null and non-safe casts return an error for the affected inputs.
   


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