kazuyukitanimura commented on code in PR #7565:
URL: https://github.com/apache/arrow-datafusion/pull/7565#discussion_r1327695964


##########
datafusion/physical-expr/src/aggregate/first_last.rs:
##########
@@ -237,13 +231,17 @@ impl Accumulator for FirstValueAccumulator {
         };
         if !ordered_states[0].is_empty() {
             let first_row = get_row_at_idx(&ordered_states, 0)?;
-            let first_ordering = &first_row[1..];
+            // When collecting orderings, we exclude the is_set flag from the 
state.
+            let first_ordering = &first_row[1..is_set_idx];
             let sort_options = get_sort_options(&self.ordering_req);
             // Either there is no existing value, or there is an earlier 
version in new data.
             if !self.is_set
                 || compare_rows(first_ordering, &self.orderings, 
&sort_options)?.is_lt()

Review Comment:
   Actually I found the only time `self.orderings` can be longer is right after 
the creation by `try_new()`. But at the time it is `self.is_set = false`, so it 
will not hit `compare_rows`. Then `self.orderings` is updated by 
`first_ordering`. So I agree that this should work.



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