You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/09 10:01:24 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3046: Replace remaining _generic temporal kernels with _dyn kernels

tustvold commented on code in PR #3046:
URL: https://github.com/apache/arrow-rs/pull/3046#discussion_r1017721822


##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -362,45 +368,52 @@ where
     T: ArrowTemporalType + ArrowNumericType,
     i64: From<T::Native>,
 {
-    month_generic::<T, _>(array)
+    month_internal(array)
 }
 
-/// Extracts the month of a given temporal array as an array of integers
-pub fn month_generic<T, A: ArrayAccessor<Item = T::Native>>(
-    array: A,
-) -> Result<Int32Array>
-where
-    T: ArrowTemporalType + ArrowNumericType,
-    i64: From<T::Native>,
-{
+/// Extracts the month of a given temporal array as an array of integers.
+/// If the given array isn't temporal primitive or dictionary array,
+/// an `Err` will be returned.
+pub fn month_dyn(array: &dyn Array) -> Result<ArrayRef> {
     match array.data_type().clone() {
-        DataType::Dictionary(_, value_type) => {
-            month_internal::<T, A>(array, value_type.as_ref())
+        DataType::Dictionary(_, _) => {
+            downcast_dictionary_array!(
+                array => {
+                    let month_values = month_dyn(array.values())?;
+                    Ok(Arc::new(array.with_values(&month_values)))
+                }
+                dt => return_compute_error_with!("month does not support", dt),
+            )
+        }
+        _ => {
+            downcast_temporal_array!(
+                array => {
+                   month_internal(array)
+                    .map(|a| Arc::new(a) as ArrayRef)
+                }
+                dt => return_compute_error_with!("month does not support", dt),
+            )
         }
-        dt => month_internal::<T, A>(array, &dt),
     }
 }
 
 /// Extracts the month of a given temporal array as an array of integers
-fn month_internal<T, A: ArrayAccessor<Item = T::Native>>(
-    array: A,
-    dt: &DataType,
-) -> Result<Int32Array>
+fn month_internal<T>(array: &PrimitiveArray<T>) -> Result<Int32Array>

Review Comment:
   It occurs to me that these `_internal` methods are no longer necessary



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org