viirya commented on code in PR #2623:
URL: https://github.com/apache/arrow-rs/pull/2623#discussion_r961907131


##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -172,109 +173,227 @@ pub fn using_chrono_tz_and_utc_naive_date_time(
 }
 
 /// Extracts the hours of a given temporal array as an array of integers
-pub fn hour<T>(array: &PrimitiveArray<T>) -> Result<Int32Array>
+pub fn hour<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> 
Result<Int32Array>
 where
     T: ArrowTemporalType + ArrowNumericType,
+    T::Native: ArrowNativeType,
+    i64: std::convert::From<T::Native>,
+{
+    match array.data_type().clone() {
+        DataType::Dictionary(_, value_type) => {
+            hour_internal::<T, A>(array, value_type.as_ref().clone())
+        }
+        dt => hour_internal::<T, A>(array, dt),
+    }
+}
+
+/// Extracts the hours of a given temporal array as an array of integers
+fn hour_internal<T, A: ArrayAccessor<Item = T::Native>>(
+    array: A,
+    dt: DataType,
+) -> Result<Int32Array>
+where
+    T: ArrowTemporalType + ArrowNumericType,
+    T::Native: ArrowNativeType,
     i64: std::convert::From<T::Native>,
 {
     let mut b = Int32Builder::with_capacity(array.len());
-    match array.data_type() {
-        &DataType::Time32(_) | &DataType::Time64(_) => {
-            extract_component_from_array!(array, b, hour, value_as_time, |h| h 
as i32)
+    match dt {
+        DataType::Time32(_) | DataType::Time64(_) => {
+            let iter = ArrayIter::new(array);
+            extract_component_from_array!(
+                iter,
+                b,
+                hour,
+                |value| as_time::<T>(i64::from(value)),
+                |h| h as i32
+            );
         }
-        &DataType::Date32 | &DataType::Date64 | &DataType::Timestamp(_, None) 
=> {
-            extract_component_from_array!(array, b, hour, value_as_datetime, 
|h| h as i32)
+        DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
+            let iter = ArrayIter::new(array);
+            extract_component_from_array!(
+                iter,
+                b,
+                hour,
+                |value| as_datetime::<T>(i64::from(value)),
+                |h| h as i32
+            )
         }
-        &DataType::Timestamp(_, Some(ref tz)) => {
+        DataType::Timestamp(_, Some(tz)) => {
             let mut scratch = Parsed::new();
+            let iter = ArrayIter::new(array);
             extract_component_from_array!(
-                array,
+                iter,
                 b,
                 hour,
-                value_as_datetime_with_tz,
+                |value, tz| as_datetime::<T>(i64::from(value))
+                    .map(|datetime| datetime + tz),
                 tz,
                 scratch,
+                |value| as_datetime::<T>(i64::from(value)),
                 |h| h as i32
             )
         }
-        dt => return_compute_error_with!("hour does not support", dt),
+        _ => return_compute_error_with!("hour does not support", 
array.data_type()),
     }
 
     Ok(b.finish())
 }
 
 /// Extracts the years of a given temporal array as an array of integers
-pub fn year<T>(array: &PrimitiveArray<T>) -> Result<Int32Array>
+pub fn year<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> 
Result<Int32Array>
+where
+    T: ArrowTemporalType + ArrowNumericType,
+    T::Native: ArrowNativeType,

Review Comment:
   Removed.



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