mbutrovich commented on code in PR #11199:
URL: https://github.com/apache/arrow-rs/pull/11199#discussion_r4106468965


##########
arrow-cast/src/cast/mod.rs:
##########
@@ -645,11 +731,16 @@ fn timestamp_to_date32<T: ArrowTimestampType>(
                     .map(|d| Date32Type::from_naive_date(d.date_naive()))
             })?
         }
-        None => array.try_unary(|x| {
-            as_datetime::<T>(x)
-                .ok_or_else(|| err(x))
-                .map(|d| Date32Type::from_naive_date(d.date()))
-        })?,
+        None => {
+            // Date32 stores days since the epoch. Round down so that a 
timestamp
+            // just before the epoch belongs to the preceding day.
+            let days = |x: i64| x.div_euclid(SECONDS_IN_DAY * 
time_unit_multiple(&T::UNIT));
+            match T::UNIT {
+                // Every microsecond or nanosecond timestamp lies within the 
Date32 range.
+                TimeUnit::Microsecond | TimeUnit::Nanosecond => 
array.unary(|x| days(x) as i32),
+                _ => array.try_unary(|x| i32::try_from(days(x)).map_err(|_| 
err(x)))?,

Review Comment:
   Would this solution apply for 
https://github.com/apache/arrow-rs/pull/11187#discussion_r4098157566?



-- 
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]

Reply via email to