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 as
they now have the same signature as the non `_internal` methods
--
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]