pepijnve commented on code in PR #16319: URL: https://github.com/apache/datafusion/pull/16319#discussion_r2136197682
########## datafusion/physical-plan/src/sorts/sort.rs: ########## @@ -1126,14 +1127,20 @@ impl ExecutionPlan for SortExec { Ok(Box::pin(RecordBatchStreamAdapter::new( self.schema(), futures::stream::once(async move { - while let Some(batch) = input.next().await { - let batch = batch?; - topk.insert_batch(batch)?; - if topk.finished { - break; + // Spawn a task the first time the stream is polled for the sort phase. + // This ensures the consumer of the sort does not poll unnecessarily + // while the sort is ongoing Review Comment: I might have gotten this completely wrong, but that should not be the case. You're correct that preparing the stream is potentially on a different thread, but what gets returned by the task is the stream itself, not the individual record batches. The stream should still be getting drained by the original task. What you're describing is what `RecordBatchReceiverStream` does which is quite different and requires channels for the inter-thread communication. -- 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