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/08 08:59:56 UTC

[GitHub] [arrow-rs] viirya opened a new pull request, #3046: Replace remaining _generic temporal kernels with _dyn kernels

viirya opened a new pull request, #3046:
URL: https://github.com/apache/arrow-rs/pull/3046

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #3004.
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


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


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

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #3046:
URL: https://github.com/apache/arrow-rs/pull/3046#discussion_r1017724762


##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -715,32 +771,46 @@ where
     T: ArrowTemporalType + ArrowNumericType,
     i64: From<T::Native>,
 {
-    time_fraction_generic::<T, _, _>(array, "nanosecond", |t| t.nanosecond() as i32)
+    time_fraction_internal(array, "nanosecond", |t| t.nanosecond() as i32)
+}
+
+/// Extracts the nanoseconds of a given temporal primitive array as an array of integers.
+/// If the given array isn't temporal primitive or dictionary array,
+/// an `Err` will be returned.
+pub fn nanosecond_dyn(array: &dyn Array) -> Result<ArrayRef> {
+    time_fraction_dyn(array, "nanosecond", |t| t.nanosecond() as i32)
 }
 
 /// Extracts the time fraction of a given temporal array as an array of integers
-fn time_fraction_generic<T, A: ArrayAccessor<Item = T::Native>, F>(
-    array: A,
-    name: &str,
-    op: F,
-) -> Result<Int32Array>
+fn time_fraction_dyn<F>(array: &dyn Array, name: &str, op: F) -> Result<ArrayRef>

Review Comment:
   I wonder if more of the kernels could be implemented using this, possibly something for a future PR



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


[GitHub] [arrow-rs] tustvold merged pull request #3046: Replace remaining _generic temporal kernels with _dyn kernels

Posted by GitBox <gi...@apache.org>.
tustvold merged PR #3046:
URL: https://github.com/apache/arrow-rs/pull/3046


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


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

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #3046:
URL: https://github.com/apache/arrow-rs/pull/3046#discussion_r1017724762


##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -715,32 +771,46 @@ where
     T: ArrowTemporalType + ArrowNumericType,
     i64: From<T::Native>,
 {
-    time_fraction_generic::<T, _, _>(array, "nanosecond", |t| t.nanosecond() as i32)
+    time_fraction_internal(array, "nanosecond", |t| t.nanosecond() as i32)
+}
+
+/// Extracts the nanoseconds of a given temporal primitive array as an array of integers.
+/// If the given array isn't temporal primitive or dictionary array,
+/// an `Err` will be returned.
+pub fn nanosecond_dyn(array: &dyn Array) -> Result<ArrayRef> {
+    time_fraction_dyn(array, "nanosecond", |t| t.nanosecond() as i32)
 }
 
 /// Extracts the time fraction of a given temporal array as an array of integers
-fn time_fraction_generic<T, A: ArrayAccessor<Item = T::Native>, F>(
-    array: A,
-    name: &str,
-    op: F,
-) -> Result<Int32Array>
+fn time_fraction_dyn<F>(array: &dyn Array, name: &str, op: F) -> Result<ArrayRef>

Review Comment:
   I wonder if more of the kernels could be implemented using this



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


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

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #3046:
URL: https://github.com/apache/arrow-rs/pull/3046#issuecomment-1308530918

   Benchmark runs are scheduled for baseline = 6057cf7ead11d66c7eeb15aed965b632afff07c4 and contender = 232fccc69ede31bc263f91d077a482ad38574304. 232fccc69ede31bc263f91d077a482ad38574304 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/e6cc2706615e4edb8fa543240d47b1f5...c2af38fd9aea46d9b92ab7b3d169a3b8/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/03101ea9fa504de090325420192ef1fd...f7c5ee4c9aae4c5aae9136764e491ab3/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/4e325f984f4845198a31553c0ad15dd6...ff593f5d35154e29a3f8d3e921aafd76/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/9de494f962ea493c85ff5aec6f7bc5fd...36a273398808444d9ac1d85b5a517a8b/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


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


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

Posted by GitBox <gi...@apache.org>.
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


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

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

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


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

Posted by GitBox <gi...@apache.org>.
viirya commented on PR #3046:
URL: https://github.com/apache/arrow-rs/pull/3046#issuecomment-1309156274

   > Presume it is already on your radar, but following this I think `extract_component_from_datetime_array` can be simplified to use `PrimitiveArray::unary`
   
   Yea, I will do some cleanup later for this and probably for https://github.com/apache/arrow-rs/pull/3046#discussion_r1017724762.
   


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