fix: validate decimal default fits the field precision#809
Open
huan233usc wants to merge 1 commit into
Open
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.
What
SchemaField::Validateaccepts a decimal default whose unscaled value does not fit the field's declared precision, even though the JSON reader rejects exactly that value on read-back — so a validated field can serialize to metadata that the same reader then refuses to parse.Example: a
decimal(2, 1)field with aninitial-defaultofLiteral::Decimal(999, 2, 1)(99.9, which needs 3 significant digits).ValidateDefaultonly checked that the literal's type matches the field type (decimal(2,1) == decimal(2,1)), so it passed; the value was serialized to"99.9"; on read-backDecimal::FromStringyields precision 3 > 2 and the decimal literal parser (expression/json_serde.cc, andLiteral::CastTo) rejects it. The field's own metadata becomes unreadable.How
ValidateDefaultnow checksDecimal::FitsInPrecision(field precision)for decimal defaults after the type-equality check, rejecting an out-of-range value up front so it is consistent with what the reader accepts. This mirrors the same guard already applied when casting defaults during schema evolution.Testing
SchemaFieldTest.ValidateRejectsDecimalDefaultExceedingPrecision(rejects99.9fordecimal(2,1)) andValidateAcceptsDecimalDefaultWithinPrecision(accepts a fitting value), verified fail-without / pass-with. Fullschema_testpasses (551 tests).