blaginin commented on code in PR #14402: URL: https://github.com/apache/datafusion/pull/14402#discussion_r1938293491
########## datafusion/functions-aggregate/src/first_last.rs: ########## @@ -627,24 +607,19 @@ impl Accumulator for LastValueAccumulator { // last index contains is_set flag. let is_set_idx = states.len() - 1; let flags = states[is_set_idx].as_boolean(); - let filtered_states = filter_states_according_to_is_set(states, flags)?; + let filtered_states = + filter_states_according_to_is_set(&states[0..is_set_idx], flags)?; // 1..is_set_idx range corresponds to ordering section - let sort_cols = convert_to_sort_cols( + let sort_columns = convert_to_sort_cols( &filtered_states[1..is_set_idx], self.ordering_req.as_ref(), ); - let ordered_states = if sort_cols.is_empty() { - // When no ordering is given, use existing state as is: - filtered_states - } else { - let indices = lexsort_to_indices(&sort_cols, None)?; - take_arrays(&filtered_states, &indices, None)? - }; + let comparator = LexicographicalComparator::try_new(&sort_columns)?; Review Comment: In `lexsort_to_indices` there are some additional optimizations when there's just one column - so I also wrote a [version which reuses](https://github.com/apache/datafusion/compare/main...blaginin:chore/alternative-reuse-lexort?expand=1) `lexsort_to_indices` - but the speed increase there is actually 20% smaller than here -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org