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 Utf8 to decimal failure #5127

Closed
Weijun-H opened this issue Nov 27, 2023 · 2 comments · Fixed by #5128
Closed

cast Utf8 to decimal failure #5127

Weijun-H opened this issue Nov 27, 2023 · 2 comments · Fixed by #5128
Labels
arrow Changes to the arrow crate bug good first issue Good for newcomers help wanted

Comments

@Weijun-H
Copy link
Member

Weijun-H commented Nov 27, 2023

Describe the bug

arrow cannot cast Utf8 to decimal correctly in #8326.

// Negative number is wrong
❯ select '-1.23499999'::DECIMAL(4,3);
+---------------------+
| Utf8("-1.23499999") |
+---------------------+
| -0.765              |
+---------------------+
1 row in set. Query took 0.032 seconds.

The problem is that arrow does not parse the string correctly.
fn parse_string_to_decimal_native<T: DecimalType>(

To Reproduce

    #[test]
    fn test() {
        let array = LargeStringArray::from(vec![Some("-0.12345")]);

        // Decimal128
        let output_type = DataType::Decimal128(38, 2);
        assert!(can_cast_types(array.data_type(), &output_type));

        let casted_array = cast(&array, &output_type).unwrap();
        let decimal_arr = casted_array.as_primitive::<Decimal128Type>();

        assert_eq!("-0.12", decimal_arr.value_as_string(0));

        // Decimal256
        let output_type = DataType::Decimal256(76, 3);
        assert!(can_cast_types(array.data_type(), &output_type));

        let casted_array = cast(&array, &output_type).unwrap();
        let decimal_arr = casted_array.as_primitive::<Decimal256Type>();

        assert_eq!("-0.123.", decimal_arr.value_as_string(0));
    }

Expected behavior

pass the test

Additional context

#8326

@Weijun-H Weijun-H added the bug label Nov 27, 2023
@Weijun-H Weijun-H changed the title cast Utf8 to negative decimal failure cast Utf8 to decimal failure Nov 27, 2023
@tustvold
Copy link
Contributor

Looks like this is adding 1 instead of -1 when combining the decimal and numeric components

@tustvold
Copy link
Contributor

tustvold commented Jan 5, 2024

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

@tustvold tustvold added the arrow Changes to the arrow crate label Jan 5, 2024
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 good first issue Good for newcomers help wanted
Projects
None yet
2 participants