We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6301344 commit e3b1045Copy full SHA for e3b1045
1 file changed
datafusion/physical-plan/src/aggregates/row_hash.rs
@@ -1036,7 +1036,19 @@ 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 {
1042
+ GroupOrdering::None => n,
1043
+ _ => match self.group_ordering.emit_to() {
1044
+ Some(EmitTo::First(max)) => n.min(max),
1045
+ _ => 0,
1046
+ },
1047
+ };
1048
+
1049
+ if n > 0
1050
+ && let Some(batch) = self.emit(EmitTo::First(n), false)?
1051
+ {
1052
Ok(Some(ExecutionState::ProducingOutput(batch)))
1053
} else {
1054
Err(oom)
0 commit comments