Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip empty batch while inserting #4

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion datafusion/src/physical_plan/sorts/sort_preserving_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ impl SortPreservingMergeStream {
// Cursor is not finished - don't need a new RecordBatch yet
return Poll::Ready(Ok(()));
}
let mut empty_batch = false;
{
let mut streams = self.streams.streams.lock().unwrap();

let stream = &mut streams[idx];
Expand All @@ -424,6 +426,7 @@ impl SortPreservingMergeStream {
return Poll::Ready(Err(e));
}
Some(Ok(batch)) => {
if batch.num_rows() > 0 {
let cursor = match SortKeyCursor::new(
idx,
self.next_batch_id, // assign this batch an ID
Expand All @@ -433,18 +436,28 @@ impl SortPreservingMergeStream {
) {
Ok(cursor) => cursor,
Err(e) => {
return Poll::Ready(Err(ArrowError::ExternalError(Box::new(e))));
return Poll::Ready(Err(ArrowError::ExternalError(
Box::new(e),
)));
}
};
self.next_batch_id += 1;
self.min_heap.push(cursor);
self.cursor_finished[idx] = false;
self.batches[idx].push_back(batch)
} else {
empty_batch = true;
}
}
}
}

if empty_batch {
self.maybe_poll_stream(cx, idx)
} else {
Poll::Ready(Ok(()))
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes above seem scary, but indent thing, an empty_batch flag is introduced, and call this method again to skip empty batches.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 The changes may be clearer by using "whitespace blind" diff: https://github.com/alamb/arrow-datafusion/pull/4/files?w=1

}

/// Drains the in_progress row indexes, and builds a new RecordBatch from them
///
Expand Down