alamb commented on a change in pull request #8215:
URL: https://github.com/apache/arrow/pull/8215#discussion_r491188026



##########
File path: rust/arrow/src/compute/kernels/aggregate.rs
##########
@@ -19,9 +19,44 @@
 
 use std::ops::Add;
 
-use crate::array::{Array, PrimitiveArray};
+use crate::array::{
+    Array, LargeStringArray, PrimitiveArray, StringArray, StringArrayOps,
+};
 use crate::datatypes::ArrowNumericType;
 
+/// Helper macro to perform min/max of strings
+macro_rules! min_max_string_helper {
+    ($array:expr, $cmp:tt) => {{
+        let null_count = $array.null_count();
+
+        if null_count == $array.len() {
+            return None
+        }
+        let mut n = "";
+        let mut has_value = false;

Review comment:
       I think you could also use an option here rather than a flag + value.
   
   So something like `let mut n = None;`
   
   And then instead of 
   
   ```
                       has_value = true;
                       n = item;
   ``` 
   something like
   ```
                       n = Some(item);
   ```

##########
File path: rust/arrow/src/compute/kernels/aggregate.rs
##########
@@ -19,9 +19,44 @@
 
 use std::ops::Add;
 
-use crate::array::{Array, PrimitiveArray};
+use crate::array::{
+    Array, LargeStringArray, PrimitiveArray, StringArray, StringArrayOps,
+};
 use crate::datatypes::ArrowNumericType;
 
+/// Helper macro to perform min/max of strings
+macro_rules! min_max_string_helper {
+    ($array:expr, $cmp:tt) => {{
+        let null_count = $array.null_count();
+
+        if null_count == $array.len() {
+            return None
+        }
+        let mut n = "";
+        let mut has_value = false;
+        let data = $array.data();
+
+        if null_count == 0 {
+            for i in 0..data.len() {
+                let item = $array.value(i);
+                if !has_value || (&n $cmp &item) {
+                    has_value = true;
+                    n = item;
+                }
+            }
+        } else {
+            for i in 0..data.len() {
+                let item = $array.value(i);
+                if data.is_valid(i) && (!has_value || (&n $cmp &item)) {
+                    has_value = true;
+                    n = item;
+                }
+            }
+        }
+        Some(n)

Review comment:
       then you could return n directly




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

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


Reply via email to