Skip to content

Cast: overflow when converting Date32 -> Timestamp #9824

@bboissin

Description

@bboissin

Describe the bug

When converting a Date32 outside the range of usec or nanos, cast()/cast_with_options() overflows.

To Reproduce

#[test]
fn test_cast_date32_to_timestamp_ns_overflow() {
    // 2262-04-11, 2062-04-12
    let a = Date32Array::from(vec![Some(106751), Some(106752), None]);
    let array = Arc::new(a) as ArrayRef;
    let err = cast_with_options(
        &array,
        &DataType::Timestamp(TimeUnit::Nanosecond, None),
        &CastOptions {
            safe: false,
            format_options: FormatOptions::default(),
        },
    );
    assert!(err.is_err());

    let b = cast(&array, &DataType::Timestamp(TimeUnit::Nanosecond, None)).unwrap();
    let c = b
        .as_any()
        .downcast_ref::<TimestampNanosecondArray>()
        .unwrap();
    assert_eq!(9223286400000000000, c.value(0));
    assert!(c.is_null(1));
    assert!(c.is_null(2));
}

Expected behavior

Behaves similar to the unittest instead of panicing.

Additional context

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions