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/02 03:26:13 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2996: `arrow::compute::kernels::temporal` should support nanoseconds

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


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

Review Comment:
   I think we have lost this function?



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

Review Comment:
   Perhaps we could call this something like unary_timestamp or something? I would also not make it public, so we can alter it down the line



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



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