Fix round() precision loss and errors for large Int64/UInt64 values#22927
Open
greedAuguria wants to merge 1 commit into
Open
Fix round() precision loss and errors for large Int64/UInt64 values#22927greedAuguria wants to merge 1 commit into
greedAuguria wants to merge 1 commit into
Conversation
round() previously coerced integer inputs through Float64, which loses precision for Int64 values above 2^53 (round(9007199254740993) returned 9007199254740992.0) and errors outright for UInt64 values above i64::MAX (round(18446744073709551615) failed instead of being a no-op). Integers now keep their own types through round(): the return type for integer inputs is the input type itself, making round(x) and round(x, n >= 0) identity-preserving for all integer values without a Float64 round-trip, while preserving the existing negative-scale rounding semantics and float behavior. Adds regression tests for both reported cases. Fixes apache#22696
Contributor
|
we already have a PR for this issue |
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?
Closes #22696.
Rationale for this change
round()coerced integer inputs throughFloat64, which loses precision forInt64values above 2^53 (round(9007199254740993)returned9007199254740992.0) and errors outright forUInt64values abovei64::MAX(round(18446744073709551615)failed instead of being a no-op).What changes are included in this PR?
Integers keep their own types through
round(): the return type for integer inputs is the input type itself, makinground(x)andround(x, n >= 0)identity-preserving for all integer values without aFloat64round-trip. Existing negative-scale rounding semantics and float behavior are preserved.Are these changes tested?
Yes — regression tests added for both reported cases (
cargo test -p datafusion-functions round: 8 passed, 0 failed).Are there any user-facing changes?
round()on integer inputs now returns the integer input type instead ofFloat64.