fix: support decimal datum conversion by precision#2508
Open
abnobdoss wants to merge 2 commits into
Open
Conversation
904a5e6 to
6805d7b
Compare
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?
What changes are included in this PR?
This fixes decimal datum precision handling in two places.
First,
Datum::to()can now convert between decimal types with the same scale and different precision, as long as the value fits the target precision. This is needed when a decimal literal is created before the target column precision is known.Second, this fixes a correctness issue in
Datum::decimal_with_precision. It previously checked whether the mantissa fit the storage byte width for the requested precision, but that could accept values that exceeded thedeclared decimal precision. It now checks the mantissa’s decimal digit count directly. For example,
0.42has mantissa42, so it does not fitdecimal(1, 2).Scale conversion remains out of scope. Decimal conversions with different source and target scales still return
DataInvalid.Are these changes tested?
Yes. This adds unit coverage for decimal precision calculation and decimal datum conversion.
Validation run:
Was generative AI tooling used to co-author this PR?
Yes.