koriyoshi2041 commented on code in PR #26788:
URL: https://github.com/apache/datafusion/pull/26788#discussion_r4584084660
##########
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:
Fixed in `9c1189b22`: the stream now clears buffered input batches
immediately after materialization and before its first yield. I also added a
two-batch weak-reference regression that keeps the output stream alive after
the first 4-row slice and verifies both original primitive arrays have been
released. The focused window suite passes 3/3.
--
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]