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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to