huaxingao commented on code in PR #9411:
URL: https://github.com/apache/arrow-datafusion/pull/9411#discussion_r1510354372


##########
datafusion/physical-expr/src/aggregate/first_last.rs:
##########
@@ -213,6 +235,7 @@ struct FirstValueAccumulator {
     ordering_req: LexOrdering,
     // Stores whether incoming data already satisfies the ordering requirement.
     requirement_satisfied: bool,
+    is_ignore_null: bool,

Review Comment:
   Added. Thanks



##########
datafusion/physical-expr/src/aggregate/first_last.rs:
##########
@@ -249,7 +274,18 @@ impl FirstValueAccumulator {
         };
         if self.requirement_satisfied {
             // Get first entry according to the pre-existing ordering (0th 
index):
-            return Ok((!value.is_empty()).then_some(0));
+            if self.is_ignore_null {
+                // If ignoring nulls, find the first non-null value.
+                for i in 0..value.len() {
+                    if !value.is_null(i) {
+                        return Ok((!value.is_empty()).then_some(i));

Review Comment:
   Fixed. Thanks



##########
datafusion/physical-expr/src/aggregate/first_last.rs:
##########
@@ -259,8 +295,20 @@ impl FirstValueAccumulator {
                 options: Some(req.options),
             })
             .collect::<Vec<_>>();
-        let indices = lexsort_to_indices(&sort_columns, Some(1))?;
-        Ok((!indices.is_empty()).then_some(indices.value(0) as _))
+
+        if self.is_ignore_null {
+            let indices = lexsort_to_indices(&sort_columns, 
Some(value.len()))?;
+            // If ignoring nulls, find the first non-null value.
+            for index in indices.iter().flatten() {
+                if !value.is_null(index as usize) {
+                    return Ok((!value.is_empty()).then_some(index as usize));

Review Comment:
   Fixed



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