Skip to content

Support casting negative scale decimals to numeric #9201

Closed

Description

@Jefffrey

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

Casting of decimals with negative scale

Describe the solution you'd like

Example test:

// 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)]
        );
    }

Currently this fails with error:

failures:

---- cast::tests::test_cast_decimal_to_numeric_negative_scale stdout ----

thread 'cast::tests::test_cast_decimal_to_numeric_negative_scale' (5901100) panicked at arrow-cast/src/cast/mod.rs:3725:9:
called `Result::unwrap()` on an `Err` value: CastError("Cannot cast to \"Decimal256\". The scale -1 causes overflow.")


failures:
    cast::tests::test_cast_decimal_to_numeric_negative_scale

test result: FAILED. 304 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

error: test failed, to rerun pass `-p arrow-cast --lib`

Would be nice if we can make this work.

Describe alternatives you've considered

Additional context

Related code section

let div: D::Native = base.pow_checked(scale as u32).map_err(|_| {
ArrowError::CastError(format!(
"Cannot cast to {:?}. The scale {} causes overflow.",
D::PREFIX,
scale,
))
})?;

Activity

  1. added
    enhancement
    on Jan 16, 2026
  2. added a commit that references this issue on Jan 26, 2026
    40f69b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions