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/08/24 21:55:55 UTC

[GitHub] [arrow-rs] viirya opened a new pull request, #2585: Add max_dyn and min_dyn for max/min for dictionary array

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

   # 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 #2584.
   
   # 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] viirya commented on a diff in pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,68 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>

Review Comment:
   Renamed to min_array, max_array and sum_array



-- 
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 a diff in pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,70 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
+where
+    T: ArrowNumericType,
+    T::Native: Add<Output = T::Native>,
+{
+    match array.data_type() {
+        DataType::Dictionary(_, _) => {
+            let null_count = array.null_count();
+
+            if null_count == array.len() {
+                return None;
+            }
+
+            let mut has_value = false;
+            let mut n = T::default_value();
+            let iter = ArrayIter::new(array);
+            iter.into_iter().for_each(|value| {
+                if let Some(value) = value {
+                    if !has_value || value < n {
+                        has_value = true;
+                        n = value;
+                    }
+                }
+            });
+
+            Some(n)
+        }
+        _ => min::<T>(as_primitive_array(&array)),
+    }
+}
+
+/// Returns the max of values in the array.
+pub fn max_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>

Review Comment:
   Added a helper function.



-- 
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 a diff in pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,68 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>

Review Comment:
   Hmm, `min_of_array`?



-- 
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] sunchao commented on a diff in pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,70 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
+where
+    T: ArrowNumericType,
+    T::Native: Add<Output = T::Native>,
+{
+    match array.data_type() {
+        DataType::Dictionary(_, _) => {
+            let null_count = array.null_count();
+
+            if null_count == array.len() {
+                return None;
+            }
+
+            let mut has_value = false;
+            let mut n = T::default_value();
+            let iter = ArrayIter::new(array);
+            iter.into_iter().for_each(|value| {
+                if let Some(value) = value {
+                    if !has_value || value < n {
+                        has_value = true;
+                        n = value;
+                    }
+                }
+            });
+
+            Some(n)
+        }
+        _ => min::<T>(as_primitive_array(&array)),
+    }
+}
+
+/// Returns the max of values in the array.
+pub fn max_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>

Review Comment:
   we may combine these two methods since they look mostly the same.



##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,70 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
+where
+    T: ArrowNumericType,
+    T::Native: Add<Output = T::Native>,
+{
+    match array.data_type() {
+        DataType::Dictionary(_, _) => {
+            let null_count = array.null_count();
+
+            if null_count == array.len() {
+                return None;
+            }
+
+            let mut has_value = false;
+            let mut n = T::default_value();
+            let iter = ArrayIter::new(array);
+            iter.into_iter().for_each(|value| {
+                if let Some(value) = value {
+                    if !has_value || value < n {

Review Comment:
   hmm does this handle NaN?



-- 
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 #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,68 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>

Review Comment:
   Typically the _dyn kernels take a trait object, these don't appear to. Perhaps we could choose a different name?



-- 
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 #2585: Add max_dyn and min_dyn for max/min for dictionary array

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

   cc @sunchao 


-- 
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 #2585: Add max_dyn and min_dyn for max/min for dictionary array

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

   Benchmark runs are scheduled for baseline = 8eea918a537bb0d82c5bc7734df4b8d2a8274268 and contender = c64ca4f24fd7ff049d5a750118b6afc164f70fa4. c64ca4f24fd7ff049d5a750118b6afc164f70fa4 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/b18cb657450b4bdcbce67240fc43ef6a...55c4f78be15c49798c0ff9997becaa83/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/75f82740f2994b5985ee7ec2296fd0ae...342348131b3f411986ea9932da3d20d3/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/88c3cb2c438c41118c8211f8b2a95563...1417cec6a9934cb3a85cf4859839c9aa/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/7523ca8ffa424e4b9692b334211ba710...2a33d2b266434c6c8ee064c16bd533bc/)
   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] viirya commented on a diff in pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,70 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
+where
+    T: ArrowNumericType,
+    T::Native: Add<Output = T::Native>,
+{
+    match array.data_type() {
+        DataType::Dictionary(_, _) => {
+            let null_count = array.null_count();
+
+            if null_count == array.len() {
+                return None;
+            }
+
+            let mut has_value = false;
+            let mut n = T::default_value();
+            let iter = ArrayIter::new(array);
+            iter.into_iter().for_each(|value| {
+                if let Some(value) = value {
+                    if !has_value || value < n {

Review Comment:
   Handled it now and added a test.



-- 
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 a diff in pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,68 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>

Review Comment:
   I guess that we have separate `min` for different type of arrays because there was no common accessor previously.
   
   But the `min` for primitive array, it has simd and non simd versions. I'm hesitant to replace them with this `ArrayAccessor` version. Do you think it is okay?



-- 
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 a diff in pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,70 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
+where
+    T: ArrowNumericType,
+    T::Native: Add<Output = T::Native>,
+{
+    match array.data_type() {
+        DataType::Dictionary(_, _) => {
+            let null_count = array.null_count();
+
+            if null_count == array.len() {
+                return None;
+            }
+
+            let mut has_value = false;
+            let mut n = T::default_value();
+            let iter = ArrayIter::new(array);
+            iter.into_iter().for_each(|value| {
+                if let Some(value) = value {
+                    if !has_value || value < n {

Review Comment:
   No, this is basically to add dictionary support. We can consider NaN later.



-- 
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 #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,68 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>

Review Comment:
   I wonder if we can't just have a single `min` kernel for all types? We currently have separate implementations for strings, primitives, etc... which is no longer needed?



-- 
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 merged pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


-- 
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 #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,68 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>

Review Comment:
   I think lets press forward with this PR as is, but renamed to `min_array`, and I'll write up a ticket to look into 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] tustvold commented on a diff in pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,68 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_array<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
+where
+    T: ArrowNumericType,
+    T::Native: ArrowNativeType,
+{
+    min_max_dyn_helper::<T, A, _, _>(
+        array,
+        |a, b| (!is_nan(*a) & is_nan(*b)) || a < b,
+        min,
+    )
+}
+
+/// Returns the max of values in the array.
+pub fn max_array<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
+where
+    T: ArrowNumericType,
+    T::Native: ArrowNativeType,
+{
+    min_max_dyn_helper::<T, A, _, _>(
+        array,
+        |a, b| (is_nan(*a) & !is_nan(*b)) || a > b,
+        max,
+    )
+}
+
+fn min_max_dyn_helper<T, A: ArrayAccessor<Item = T::Native>, F, M>(

Review Comment:
   ```suggestion
   fn min_max_array_helper<T, A: ArrayAccessor<Item = T::Native>, F, M>(
   ```



-- 
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 a diff in pull request #2585: Add max_dyn and min_dyn for max/min for dictionary array

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


##########
arrow/src/compute/kernels/aggregate.rs:
##########
@@ -215,6 +215,70 @@ where
     }
 }
 
+/// Returns the min of values in the array.
+pub fn min_dyn<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
+where
+    T: ArrowNumericType,
+    T::Native: Add<Output = T::Native>,
+{
+    match array.data_type() {
+        DataType::Dictionary(_, _) => {
+            let null_count = array.null_count();
+
+            if null_count == array.len() {
+                return None;
+            }
+
+            let mut has_value = false;
+            let mut n = T::default_value();
+            let iter = ArrayIter::new(array);
+            iter.into_iter().for_each(|value| {
+                if let Some(value) = value {
+                    if !has_value || value < n {

Review Comment:
   Oh oh, we should add `(!is_nan(*a) & is_nan(*b))` like `max` and `min`.



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