tustvold commented on code in PR #4301:
URL: https://github.com/apache/arrow-datafusion/pull/4301#discussion_r1028358218
##########
datafusion/core/src/physical_plan/sorts/sort_preserving_merge.rs:
##########
@@ -570,45 +606,57 @@ impl SortPreservingMergeStream {
let _timer = elapsed_compute.timer();
loop {
- match self.heap.pop() {
- Some(Reverse(mut cursor)) => {
- let stream_idx = cursor.stream_idx();
- let batch_idx = self.batches[stream_idx].len() - 1;
- let row_idx = cursor.advance();
-
- let mut cursor_finished = false;
- // insert the cursor back to heap if the record batch is
not exhausted
- if !cursor.is_finished() {
- self.heap.push(Reverse(cursor));
- } else {
- cursor_finished = true;
- self.cursor_finished[stream_idx] = true;
+ // Adjust the loser tree if necessary
+ if !self.loser_tree_adjusted {
+ let mut winner = self.loser_tree[0];
Review Comment:
It might be easier to follow if this was moved into a method called
`replace_loser_tree_winner`, perhaps with a link to this GIF -
https://en.wikipedia.org/wiki/K-way_merge_algorithm#/media/File:Loser_tree_replacement_selection.gif
--
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]