fix(arrow-cast): respect cast safety for overflowing temporal casts#10162
Open
SAY-5 wants to merge 1 commit into
Open
fix(arrow-cast): respect cast safety for overflowing temporal casts#10162SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Jefffrey
approved these changes
Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Two temporal cast paths ignore the cast safety option:
Time32(Second)toTime32(Millisecond)multiplies ani32by 1000 withunary, so a large value panics with "attempt to multiply with overflow" in debug and wraps in release.Date64toDate32divides byMILLISECONDS_IN_DAYand then does an uncheckedas i32, which silently truncates day counts that do not fit ini32(e.g.i64::MAXproduces-622191233).Both are reachable from
cast/cast_with_optionson valid input and do not honourCastOptions::safe.What changes are included 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_optwith a checked operation, and in non-safe mode they return aCastError/ArithmeticOverflowviatry_unary.This covers the two cases shown in the issue. Other temporal casts that multiply into
i64(e.g.Time32(Second)toTime64) cannot overflow for in-range inputs and are left unchanged.Are these changes tested?
Yes. Added
test_cast_date64_to_date32_overflowandtest_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?
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.