Skip to content

Commit 3ce1b2b

Browse files
committed
Clamp to the sort boundary when using partial group ordering
Closes #20445
1 parent 6301344 commit 3ce1b2b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

datafusion/physical-plan/src/aggregates/row_hash.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,16 @@ impl GroupedHashAggregateStream {
10361036
self.group_values.len()
10371037
};
10381038

1039-
if let Some(batch) = self.emit(EmitTo::First(n), false)? {
1039+
// Clamp to the sort boundary when using partial group ordering,
1040+
// otherwise remove_groups panics (#20445).
1041+
let n = match self.group_ordering.emit_to() {
1042+
Some(EmitTo::First(max)) => n.min(max),
1043+
_ => n,
1044+
};
1045+
1046+
if n > 0
1047+
&& let Some(batch) = self.emit(EmitTo::First(n), false)?
1048+
{
10401049
Ok(Some(ExecutionState::ProducingOutput(batch)))
10411050
} else {
10421051
Err(oom)

0 commit comments

Comments
 (0)