Jefffrey commented on code in PR #5262:
URL: https://github.com/apache/arrow-rs/pull/5262#discussion_r1438847765


##########
arrow-arith/src/temporal.rs:
##########
@@ -426,29 +403,65 @@ where
     T: ArrowTemporalType + ArrowNumericType,
     i64: From<T::Native>,
 {
-    time_fraction_internal(array, "millisecond", |t| {
+    time_fraction_internal_time(array, "millisecond", |t| {
         (t.nanosecond() / 1_000_000) as i32
     })
 }
+
 /// Extracts the milliseconds of a given temporal primitive array as an array 
of integers.
 /// If the given array isn't temporal primitive or dictionary array,
 /// an `Err` will be returned.
 pub fn millisecond_dyn(array: &dyn Array) -> Result<ArrayRef, ArrowError> {
-    time_fraction_dyn(array, "millisecond", |t| {
+    time_fraction_dyn_time(array, "millisecond", |t| {
         (t.nanosecond() / 1_000_000) as i32
     })
 }
 
-/// Extracts the time fraction of a given temporal array as an array of 
integers
-fn time_fraction_dyn<F>(array: &dyn Array, name: &str, op: F) -> 
Result<ArrayRef, ArrowError>
+/// Extracts the time fraction of a given temporal datetime array as an array 
of integers.
+///
+/// Does not support Time32/Time64, e.g. in cases when trying to extract month.
+fn time_fraction_dyn_datetime<F>(
+    array: &dyn Array,
+    name: &str,
+    op: F,
+) -> Result<ArrayRef, ArrowError>
 where
     F: Fn(NaiveDateTime) -> i32,
 {
-    match array.data_type().clone() {
+    match array.data_type() {
+        DataType::Dictionary(_, _) => {
+            downcast_dictionary_array!(
+                array => {
+                    let values = time_fraction_dyn_datetime(array.values(), 
name, op)?;
+                    Ok(Arc::new(array.with_values(values)))
+                }
+                dt => return_compute_error_with!(format!("{name} does not 
support"), dt),
+            )
+        }
+        _ => {
+            downcast_temporal_array!(
+                array => {
+                   time_fraction_internal_datetime(array, name, op)
+                    .map(|a| Arc::new(a) as ArrayRef)
+                }
+                dt => return_compute_error_with!(format!("{name} does not 
support"), dt),
+            )
+        }
+    }
+}
+
+/// Extracts the time fraction of a given temporal time array as an array of 
integers.
+///
+/// Supports Time32/Time64 types.
+fn time_fraction_dyn_time<F>(array: &dyn Array, name: &str, op: F) -> 
Result<ArrayRef, ArrowError>
+where
+    F: Fn(NaiveTime) -> i32,
+{
+    match array.data_type() {

Review Comment:
   Duplication ugly here, but wasn't sure how to reduce without falling back to 
something like macros
   
   Figured since it's only duplicated once and is internal code, might be ok 
for now?



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