wleeaf opened a new pull request, #717:
URL: https://github.com/apache/avro-rs/pull/717
Reading a bytes-backed decimal with a reader schema fails for most values.
Writer and reader are both `{"type": "bytes", "logicalType": "decimal",
"precision": 5, "scale": 2}`, and the datum is 2.56 (unscaled 256, encoded as
the two bytes `01 00`). Resolution fails:
```
from_avro_datum(&writer, &mut bytes, Some(&reader))
-> Precision 5 too small to hold decimal values with 2 bytes
```
The same happens through `GenericDatumReader` and `Reader` whenever a reader
schema is given, and for any value whose byte length is small for the declared
precision: 1.00 in a `decimal(10, 2)` (one byte) fails too. Reading without a
reader schema works, and Java reads these values.
`Value::resolve_decimal` compared `max_prec_for_len(value_length)` with the
schema's precision for every value. That bound says how many digits a fixed of
that size can always hold, which is a constraint on the fixed size of a
fixed-backed decimal. It says nothing about whether a particular value fits. A
short value always has few digits, so the check rejected the values that are
least likely to overflow. This removes the per-value check. The schema-level
check, that a fixed size can hold the precision, stays. `Decimal::len()` had no
other users and is removed with it.
Test: `resolve_decimal_value_shorter_than_precision` resolves a two-byte
`Value::Decimal` and `Value::Bytes` against `decimal(5, 2)`. It fails with the
error above without the change and passes with it. `cargo fmt --all --check`,
`cargo clippy --all-features --all-targets --workspace` and `cargo test
--all-features` pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]