Repository navigation
Commit 4bdf2eb
authored
fix: validate decimal default fits the field precision (#809)
## What
`SchemaField::Validate` accepts 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 an `initial-default` of
`Literal::Decimal(999, 2, 1)` (`99.9`, which needs 3 significant
digits). `ValidateDefault` only 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-back `Decimal::FromString` yields
precision 3 > 2 and the decimal literal parser
(`expression/json_serde.cc`, and `Literal::CastTo`) rejects it. The
field's own metadata becomes unreadable.
## How
`ValidateDefault` now checks `Decimal::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`
(rejects `99.9` for `decimal(2,1)`) and
`ValidateAcceptsDecimalDefaultWithinPrecision` (accepts a fitting
value), verified fail-without / pass-with. Full `schema_test` passes
(551 tests).1 parent 882fc17 commit 4bdf2eb
2 files changed
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
188 | 203 | | |
189 | 204 | | |
190 | 205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
206 | 225 | | |
0 commit comments