You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "mbutrovich (via GitHub)" <gi...@apache.org> on 2026/10/15 20:22:08 UTC
Re: [I] Casting decimals that exceed declared precision is buggy [arrow-rs]
mbutrovich commented on issue #10947:
URL: https://github.com/apache/arrow-rs/issues/10947#issuecomment-6201501401
The same panic also happens when every valid value fits the declared precision and only the data under a null slot does not:
```rust
use std::sync::Arc;
use arrow_array::{ArrayRef, Decimal128Array};
use arrow_buffer::{NullBuffer, ScalarBuffer};
use arrow_cast::cast::{cast_with_options, CastOptions};
use arrow_schema::DataType;
fn main() {
// [1, null], where the null slot holds a value that does not fit i64
let values = ScalarBuffer::from(vec![1i128, i128::MAX]);
let nulls = NullBuffer::from(vec![true, false]);
let a: ArrayRef = Arc::new(Decimal128Array::new(values, Some(nulls)).with_precision_and_scale(5, -2).unwrap());
let options = CastOptions { safe: true, ..Default::default() };
let _ = cast_with_options(&a, &DataType::Decimal64(18, 0), &options);
// panics: called `Option::unwrap()` on a `None` value
}
```
`make_upscaler` chooses the infallible closure when `input_precision + delta_scale <= output_precision`, and that closure unwraps `from_decimal` for every slot ([decimal.rs](https://github.com/apache/arrow-rs/blob/72887ed91c80002bb7ec755ce1e964bab07bebea/arrow-cast/src/cast/decimal.rs#L186-L194)). `unary` applies it to null slots too, whose values the spec leaves unspecified ([Columnar.rst](https://github.com/apache/arrow/blob/fcf8f3014227cafe24deeb044c2d51f5fc9902e5/docs/source/format/Columnar.rst?plain=1#L394)). Should the infallible path be taken only when the array has no nulls, or apply the fallible closure to null slots?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org