fix(decimal): use minimal byte length for negative powers of two#3523
Open
vishnuprakaz wants to merge 1 commit into
Open
fix(decimal): use minimal byte length for negative powers of two#3523vishnuprakaz wants to merge 1 commit into
vishnuprakaz wants to merge 1 commit into
Conversation
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.
Closes #3522
Rationale for this change
bytes_requiredshould return the minimum number of bytes fora value, but it returns one byte too many for negatives like
-128 and -32768.
This matters because the decimal bucket transform hashes those
bytes. The extra byte changes the hash, so PyIceberg can put a
value in a different bucket than Spark/Java. For example,
Decimal("-1.28")goes to bucket 12 in PyIceberg but bucket 13everywhere else.
The fix computes the length from
(value + 1)for negativevalues, which gives the true minimum and matches the Iceberg
spec.
Are these changes tested?
Yes. Added tests for the -128 / -32768 / -8388608 boundary cases
(where the old code was wrong) plus positive/negative controls.
Lint and the decimal/conversion/transform tests pass.
Are there any user-facing changes?
Yes. For decimal values like -1.28, the computed bucket changes
(e.g. 12 → 13) so it now matches other Iceberg engines.