kosiew commented on code in PR #26788:
URL: https://github.com/apache/datafusion/pull/26788#discussion_r4583704837
##########
datafusion/physical-plan/src/windows/window_agg_exec.rs:
##########
@@ -582,58 +585,30 @@ impl WindowAggStream {
}
}
-impl Stream for WindowAggStream {
- type Item = Result<RecordBatch>;
-
- fn poll_next(
- mut self: Pin<&mut Self>,
- cx: &mut Context<'_>,
- ) -> Poll<Option<Self::Item>> {
- let poll = self.poll_next_inner(cx);
- self.baseline_metrics.record_poll(poll)
- }
-}
-
impl WindowAggStream {
- #[inline]
- fn poll_next_inner(
- &mut self,
- cx: &mut Context<'_>,
- ) -> Poll<Option<Result<RecordBatch>>> {
- if self.finished {
- return Poll::Ready(None);
- }
-
- loop {
- return Poll::Ready(Some(match
ready!(self.input.poll_next_unpin(cx)) {
- Some(Ok(batch)) => {
- self.batches.push(batch);
- continue;
- }
- Some(Err(e)) => Err(e),
- None => {
- // Release the input pipeline's resources before computing
- // the final aggregates.
- let input_schema = self.input.schema();
- self.input =
Box::pin(EmptyRecordBatchStream::new(input_schema));
- let Some(result) = self.compute_aggregates()? else {
- return Poll::Ready(None);
- };
- self.finished = true;
- // Empty record batches should not be emitted.
- // They need to be treated as [`Option<RecordBatch>`]es
and handled separately
- debug_assert!(result.num_rows() > 0);
- Ok(result)
+ fn into_stream(mut self) -> SendableRecordBatchStream {
+ let schema = Arc::clone(&self.schema);
+ let metrics = self.baseline_metrics.clone();
+ let stream = async_try_stream(|mut emitter| async move {
+ while let Some(batch) = self.input.next().await.transpose()? {
+ self.batches.push(batch);
+ }
+ let input_schema = self.input.schema();
+ drop(std::mem::replace(
+ &mut self.input,
+ Box::pin(EmptyRecordBatchStream::new(input_schema)),
+ ));
+ if let Some(output) = self.compute_aggregates()? {
Review Comment:
The generator retains `self.batches` across output yields because the
previous `self.batches.clear()` was removed. Please clear these batches
immediately after successful `compute_aggregates()` and before the first
emission, then add a regression test using independently allocated primitive
input batches that verifies the original input array is released while the
stream remains alive after its first output slice.
--
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]