Skip to content

Conversation

@Chiicake
Copy link

Which issue does this PR close?

Rationale for this change

Casting decimals with negative scale to integer types currently errors because the scale factor is always applied as a division. Negative scales represent powers of ten that should scale the integer value up, so the cast should multiply instead.

What changes are included in this PR?

  • Apply the scale factor using multiplication when scale < 0 in cast_decimal_to_integer.

Are these changes tested?

Yes, the test given by issue is passed.

// arrow-cast/src/cast/mod.rs
    #[test]
    fn test_cast_decimal_to_numeric_negative_scale() {
        let value_array: Vec<Option<i256>> = vec![
            Some(i256::from_i128(125)),
            Some(i256::from_i128(225)),
            Some(i256::from_i128(325)),
            None,
            Some(i256::from_i128(525)),
        ];
        let array = create_decimal256_array(value_array, 38, -1).unwrap();

        generate_cast_test_case!(
            &array,
            Int64Array,
            &DataType::Int64,
            vec![Some(1_250), Some(2_250), Some(3_250), None, Some(5_250)]
        );
    }

Are there any user-facing changes?

No.

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jan 17, 2026
@Chiicake Chiicake requested a review from Jefffrey January 17, 2026 07:27
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support casting negative scale decimals to numeric

2 participants