Skip to content

Support casting negative scale decimals to numeric - #9207

Merged
alamb merged 6 commits into
mainfrom
unknown repository
Jan 26, 2026
Merged

alamb merged 6 commits into
mainfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Jan 17, 2026

Copy link
Copy Markdown

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
Comment thread arrow-cast/src/cast/decimal.rs Resolved
Comment thread arrow-cast/src/cast/mod.rs Resolved
@ghost
ghost requested a review from Jefffrey January 17, 2026 07:27
Comment thread arrow-cast/src/cast/decimal.rs Resolved
@alamb

alamb commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Looks good to me -- thank you @Chiicake and @Jefffrey

@alamb
alamb merged commit 40f69b4 into apache:main Jan 26, 2026
@ghost

ghost commented Jan 27, 2026

Copy link
Copy Markdown
Author

@Jefffrey Thank you for your detailed review!

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