Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support casting strings to Date32 that contain large dates #7073

Open
phillipleblanc opened this issue Feb 4, 2025 · 1 comment · May be fixed by #7074
Open

Support casting strings to Date32 that contain large dates #7073

phillipleblanc opened this issue Feb 4, 2025 · 1 comment · May be fixed by #7074
Assignees
Labels

Comments

@phillipleblanc
Copy link
Contributor

Describe the bug
Attempting to convert a string which contains a valid large date in the ISO format (i.e. +10999-12-31) will result in the following error:

CastError("Cannot cast string '+10999-12-31' to value of Date32 type")

According to ISO 8601:

Four digits or more for the year. Years in the range 0000 to 9999 will be pre-padded by zero to ensure four digits. Years outside that range will have a prefixed positive or negative symbol.

To Reproduce

#[test]
fn test_cast_string_with_large_date_to_date32() {
    let array = Arc::new(StringArray::from(vec![
        Some("+10999-12-31"),
        Some("-0010-02-28")
    ])) as ArrayRef;
    let to_type = DataType::Date32;
    let options = CastOptions {
        safe: false,
        format_options: FormatOptions::default(),
    };
    let b = cast_with_options(&array, &to_type, &options).unwrap();
    let c = b.as_primitive::<Date32Type>();
    assert_eq!(3298139, c.value(0));
    assert_eq!(-723122, c.value(1));
}

Expected behavior
The cast works as expected.

# for free to join this conversation on GitHub. Already have an account? # to comment