Dandandan commented on code in PR #21629:
URL: https://github.com/apache/datafusion/pull/21629#discussion_r3088547619
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -323,56 +285,188 @@ impl ExternalSorter {
self.reserve_memory_for_batch_and_maybe_spill(&input)
.await?;
- self.in_mem_batches.push(input);
+ let coalescer = self
+ .coalescer
+ .as_mut()
+ .expect("coalescer must exist during insert phase");
+ coalescer
+ .push_batch(input)
+ .map_err(|e| DataFusionError::ArrowError(Box::new(e), None))?;
+
+ self.drain_completed_batches()?;
+
+ Ok(())
+ }
+
+ /// Drains completed (full) batches from the coalescer, sorts each,
+ /// and appends the sorted chunks to `sorted_runs`.
+ fn drain_completed_batches(&mut self) -> Result<()> {
+ // Collect completed batches first to avoid borrow conflict
+ let mut completed = vec![];
+ if let Some(coalescer) = self.coalescer.as_mut() {
+ while let Some(batch) = coalescer.next_completed_batch() {
+ completed.push(batch);
+ }
+ }
+ for batch in &completed {
+ self.sort_and_store_run(batch)?;
Review Comment:
Nice - I wonder if a part of the speedup comes from this (sorting batch
immediately (while in CPU cache) instead of waiting to the end.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]