We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6301344 commit 3ce1b2bCopy full SHA for 3ce1b2b
1 file changed
datafusion/physical-plan/src/aggregates/row_hash.rs
@@ -1036,7 +1036,16 @@ impl GroupedHashAggregateStream {
1036
self.group_values.len()
1037
};
1038
1039
- if let Some(batch) = self.emit(EmitTo::First(n), false)? {
+ // 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
+ {
1049
Ok(Some(ExecutionState::ProducingOutput(batch)))
1050
} else {
1051
Err(oom)
0 commit comments