Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cast_string_to_decimal should check precision overflow #4829

Closed
jonahgao opened this issue Sep 18, 2023 · 1 comment · Fixed by #4830
Closed

cast_string_to_decimal should check precision overflow #4829

jonahgao opened this issue Sep 18, 2023 · 1 comment · Fixed by #4830
Labels
arrow Changes to the arrow crate bug

Comments

@jonahgao
Copy link
Member

Describe the bug
Casting from string to decimal does not perform a precision overflow check.

To Reproduce

use arrow::array::types::Decimal128Type;
use arrow::array::{AsArray, StringArray};
use arrow::compute::{cast_with_options, CastOptions};
use arrow::datatypes::DataType;

fn main() {
    let str_array = StringArray::from(vec!["1000".to_string()]);
    let output_type = DataType::Decimal128(10, 8);
    let mut option = CastOptions::default();
    option.safe = false;
    let casted_array = cast_with_options(&str_array, &output_type, &option).unwrap();
    let decimal_array = casted_array.as_primitive::<Decimal128Type>();
    println!("{:?}", decimal_array.value_as_string(0));
}

The execution result of the above program is "10.00000000".

Expected behavior

It should panic and report an overflow.

Additional context

@tustvold
Copy link
Contributor

label_issue.py automatically added labels {'arrow'} from #4830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants