tustvold commented on code in PR #2996:
URL: https://github.com/apache/arrow-rs/pull/2996#discussion_r1011117082
##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -717,49 +717,65 @@ where
T: ArrowTemporalType + ArrowNumericType,
i64: From<T::Native>,
{
- second_generic::<T, _>(array)
+ second_fraction_generic::<T, _, _>(array, "second", |t| t.second() as i32)
}
-/// Extracts the seconds of a given temporal array as an array of integers
-pub fn second_generic<T, A: ArrayAccessor<Item = T::Native>>(
+/// Extracts the nanoseconds of a given temporal primitive array as an array
of integers
+pub fn nanosecond<T>(array: &PrimitiveArray<T>) -> Result<Int32Array>
+where
+ T: ArrowTemporalType + ArrowNumericType,
+ i64: From<T::Native>,
+{
+ second_fraction_generic::<T, _, _>(array, "nanosecond", |t| t.nanosecond()
as i32)
+}
+
+/// Extracts the seconds fraction of a given temporal array as an array of
integers
+pub fn second_fraction_generic<T, A: ArrayAccessor<Item = T::Native>, F>(
array: A,
+ name: &str,
+ op: F,
) -> Result<Int32Array>
where
+ F: Fn(NaiveDateTime) -> i32,
T: ArrowTemporalType + ArrowNumericType,
i64: From<T::Native>,
{
match array.data_type().clone() {
DataType::Dictionary(_, value_type) => {
- second_internal::<T, A>(array, value_type.as_ref())
+ second_fraction_internal::<T, A, _>(array, value_type.as_ref(),
name, op)
}
- dt => second_internal::<T, A>(array, &dt),
+ dt => second_fraction_internal::<T, A, _>(array, &dt, name, op),
}
}
-/// Extracts the seconds of a given temporal array as an array of integers
-fn second_internal<T, A: ArrayAccessor<Item = T::Native>>(
+/// Extracts the seconds fraction of a given temporal array as an array of
integers
+fn second_fraction_internal<T, A: ArrayAccessor<Item = T::Native>, F>(
Review Comment:
It occurs to me that this function can probably be implemented more
efficiently using try_unary, probably not something for this PR though
Edit: It actually can't because of the use of ArrayAccessor :cry:
--
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]