Skip to content

Casting floating point numbers fails for Decimal64 but works for other variants #8362

@AdamGS

Description

@AdamGS

Describe the bug
Casting a floating point number like 1.1_f64 to decimal64 fails.

To Reproduce
The following test fails, but only for Decimal64.

    #[test]
    fn test_cast_floating_to_decimals() {
        for output_type in [
            DataType::Decimal32(9, 3),
            DataType::Decimal64(9, 3),
            DataType::Decimal128(9, 3),
            DataType::Decimal256(9, 3),
        ] {
            let input_type = DataType::Float64;
            assert!(can_cast_types(&input_type, &output_type));

            let array = vec![Some(1.1_f64)];
            let array = PrimitiveArray::<Float64Type>::from_iter(array);
            let result = cast_with_options(
                &array,
                &output_type,
                &CastOptions {
                    safe: false,
                    format_options: FormatOptions::default(),
                },
            );
            assert!(
                result.is_ok(),
                "Failed to cast to {output_type} with: {}",
                result.unwrap_err().to_string()
            );
        }
    }

Expected behavior
This cast operation should work for all decimal types.

Additional context

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions