mustafasrepo commented on code in PR #9801:
URL: https://github.com/apache/arrow-datafusion/pull/9801#discussion_r1538921505
##########
datafusion/physical-expr/src/aggregate/first_last.rs:
##########
@@ -611,8 +634,20 @@ impl LastValueAccumulator {
}
})
.collect::<Vec<_>>();
- let indices = lexsort_to_indices(&sort_columns, Some(1))?;
- Ok((!indices.is_empty()).then_some(indices.value(0) as _))
+
+ if self.ignore_nulls {
+ let indices = lexsort_to_indices(&sort_columns, None)?;
+ // If ignoring nulls, find the last non-null value.
+ for index in indices.iter().flatten() {
+ if !value.is_null(index as usize) {
+ return Ok(Some(index as usize));
+ }
+ }
+ Ok(None)
+ } else {
+ let indices = lexsort_to_indices(&sort_columns, Some(1))?;
+ Ok((!indices.is_empty()).then_some(indices.value(0) as _))
Review Comment:
For `last_value` sort expressions are reversed. By this trick, we can get
the first expression in the sort to get last one.
--
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]