apache / arrow-rs

Official Rust implementation of Apache Arrow
https://arrow.apache.org/
Apache License 2.0
2.47k stars 737 forks source link

Cast from Decimal(p, s) to dictionary-encoded Decimal(p, s) loses precision and scale #6381

Closed andygrove closed 2 hours ago

andygrove commented 1 week ago

Describe the bug

I have code that calls cast_with_options to cast Decimal128(7, 2) to Dictionary<Int32, Decimal128(7,2)> but it actually produces Dictionary<Int32, Decimal128(38, 10)>.

I can see that this is because we ignore the precision and scale in the code in cast_to_dictionary:

        Decimal128(_, _) => {
            pack_numeric_to_dictionary::<K, Decimal128Type>(array, dict_value_type, cast_options)
        }

To Reproduce

Expected behavior

Additional context

andygrove commented 1 week ago

I plan on submitting a PR to fix this.