mbutrovich opened a new issue, #11893: URL: https://github.com/apache/arrow-rs/issues/11893
# Describe the bug [`time64us_to_time` and `time64ns_to_time`](https://github.com/apache/arrow-rs/blob/9d7f294ca6bfa3591616059d11a3c15464a21f58/arrow-array/src/temporal_conversions.rs#L94-L113) convert the whole seconds with `as u32`. A `Time64` value of 2^32 seconds or more wraps to a time within the day instead of returning `None`. `as_time` and [`Display`](https://github.com/apache/arrow-rs/blob/9d7f294ca6bfa3591616059d11a3c15464a21f58/arrow-cast/src/display.rs#L860-L861) inherit this. Display reports an error for a value of exactly one day but prints 2^32 + 5 seconds as `00:00:05`, while [`date_part`](https://github.com/apache/arrow-rs/blob/9d7f294ca6bfa3591616059d11a3c15464a21f58/arrow-arith/src/temporal.rs#L363-L368) returns NULL for both. # To Reproduce ```rust use arrow_arith::temporal::{date_part, DatePart}; use arrow_array::temporal_conversions::{time64ns_to_time, time64us_to_time}; use arrow_array::Time64NanosecondArray; let one_day = 86_400_000_000_000_i64; let wrapped = ((1_i64 << 32) + 5) * 1_000_000_000; println!("{:?}", time64ns_to_time(one_day)); // None println!("{:?}", time64ns_to_time(wrapped)); // Some(00:00:05) println!("{:?}", time64us_to_time(wrapped / 1_000)); // Some(00:00:05) let array = Time64NanosecondArray::from(vec![one_day, wrapped]); println!("{array:?}"); println!("{:?}", date_part(&array, DatePart::Second).unwrap()); ``` On 60.0.0 this prints: ```text None Some(00:00:05) Some(00:00:05) PrimitiveArray<Time64(ns)> [ Cast error: Failed to convert 86400000000000 to temporal for Time64(ns), 00:00:05, ] PrimitiveArray<Int32> [ null, null, ] ``` # Expected behavior Both functions return `None` for any value outside one day, so display reports these values the way #5428 made it report other out-of-range times, and agrees with `date_part`. Converting the seconds with `u32::try_from(..).ok()?` would do it. # Additional context The format doesn't allow these values, but `cast` from `Int64` to `Time64` creates them without checking, which #5288 settled is allowed. I found this while working on apache/datafusion#26686. #593 reported the same `as u32` cast, including a too-large `Time` value in a later comment, and was closed as resolved by #2326, which changed only the timestamp and `Date64` functions. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
