`PrimitiveArray::validate_decimal_precision` rejects every decimal array with a negative scale
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Read arrow-array/src/array/primitive_array.rs around PrimitiveArray::validate_decimal_precision, then compare its scale guard with validate_decimal_precision_and_scale in arrow-array/src/types.rs. Add a regression test for a negative-scale Decimal128Array such as the issue’s precision 5, scale -2 case; done means that value validates successfully while existing positive-scale checks still pass.
Written by the indexing model from the issue text.
Description
Describe the bug
PrimitiveArray::validate_decimal_precision returns Decimal precision {precision} is less than scale {scale} for any array whose scale is negative, whatever its precision and values. Its guard compares precision < self.scale() as u8, and a negative scale cast to u8 wraps, so -2 becomes 254.
The type-level check validate_decimal_precision_and_scale guards the same comparison with scale > 0:
The guard came in with #8396, first released in 57.0.0.
To Reproduce
On main at cc58320c2d:
use arrow_array::Decimal128Array;
fn main() {
// 1 at scale -2 is 100, which fits in precision 5
let a = Decimal128Array::from(vec![1])
.with_precision_and_scale(5, -2)
.unwrap();
println!("{:?}", a.validate_decimal_precision(5));
// Err(InvalidArgumentError("Decimal precision 5 is less than scale -2"))
// The same value at scale 2 passes
let b = Decimal128Array::from(vec![1])
.with_precision_and_scale(5, 2)
.unwrap();
println!("{:?}", b.validate_decimal_precision(5));
// Ok(())
}
Expected behavior
Ok(()) for the first array, since its value fits precision 5. A guard of self.scale() > 0 && precision < self.scale() as u8 would match validate_decimal_precision_and_scale.
Additional context
Property-based tests found it on a generated Decimal128(5, -2) array. Checking each value with DecimalType::validate_decimal_precision works around it.
- Dominant language
- Rust
- Stars
- 3.7k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 314
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/arrow-rs
-
`substring` errors when the bytes under a null `Utf8` slot would be cut inside a characterPossibly taken @cakeni claimed this 19 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/arrow-rs#11590 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
enhancement parquet
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
i256::to_f32 double-rounds through f64May be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
apache/arrow-rs#11316 · 1 comment ·
Maintainers usually reply within 1 day
-
`null_if_overflow_precision` resets decimal precision and scale, changing valid valuesMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/arrow-rs#9657 · 4 comments ·
Maintainers usually reply within 1 day
Similar issues
-
🐞 bug 🧩 bevy_gantz_egui
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
nannou-org/gantz#500 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
metasequoiaime/msime#10989 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
fritzprix/libr-agent#2612 ·
Maintainers usually reply within 1 day
-
crate: spate-core priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NSPG13/agent-bounties#1749 ·
Maintainers usually reply within 1 day