Skip to content

Commit 21c0459

Browse files
buraksennOmega359
authored andcommitted
chore(SingleHashAggregateStream): refactor to async generator implementation (apache#24016)
## Which issue does this PR close? Does not close but part of apache#23974 ## Rationale for this change Simplify `SingleHashAggregateStream` by removing state required only for manual polling. ## What changes are included in this PR? Convert the stream to an async generator and remove the explicit state machine. ## Are these changes tested? Yes existing tests with additional metric assert ## Are there any user-facing changes? No
1 parent c17c67b commit 21c0459

2 files changed

Lines changed: 259 additions & 521 deletions

File tree

‎datafusion/physical-plan/src/aggregates/mod.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ impl From<StreamType> for SendableRecordBatchStream {
718718
StreamType::PartialHash(stream) => stream.into_stream(),
719719
StreamType::PartialReduceHash(stream) => Box::pin(stream),
720720
StreamType::FinalHash(stream) => stream.into_stream(),
721-
StreamType::SingleHash(stream) => Box::pin(stream),
721+
StreamType::SingleHash(stream) => stream.into_stream(),
722722
StreamType::OrderedPartialAggregate(stream) => stream.into_stream(),
723723
StreamType::OrderedFinalAggregate(stream) => stream.into_stream(),
724724
StreamType::OrderedSingleAggregate(stream) => Box::pin(stream),
@@ -5566,7 +5566,17 @@ mod tests {
55665566
assert!(matches!(stream, StreamType::SingleHash(_)));
55675567
let stream: SendableRecordBatchStream = stream.into();
55685568
let output = collect(stream).await?;
5569+
assert_eq!(output.len(), 2);
55695570
assert_eq!(output.iter().map(RecordBatch::num_rows).sum::<usize>(), 3);
5571+
5572+
let metrics = single.metrics().expect("aggregate metrics should exist");
5573+
assert_eq!(metrics.output_rows(), Some(3));
5574+
assert_eq!(
5575+
metrics
5576+
.sum(|metric| matches!(metric.value(), MetricValue::OutputBatches(_)))
5577+
.map(|value| value.as_usize()),
5578+
Some(2)
5579+
);
55705580
assert_snapshot!(batches_to_sort_string(&output), @r"
55715581
+---+--------+
55725582
| a | SUM(b) |

0 commit comments

Comments
 (0)