gabotechs commented on code in PR #18906:
URL: https://github.com/apache/datafusion/pull/18906#discussion_r2558858500
##########
datafusion/physical-plan/src/aggregates/group_values/row.rs:
##########
@@ -206,29 +233,43 @@ impl GroupValues for GroupValuesRows {
output
}
EmitTo::First(n) => {
- let groups_rows = group_values.iter().take(n);
- let output = self.row_converter.convert_rows(groups_rows)?;
- // Clear out first n group keys by copying them to a new Rows.
- // TODO file some ticket in arrow-rs to make this more
efficient?
- let mut new_group_values = self.row_converter.empty_rows(0, 0);
- for row in group_values.iter().skip(n) {
- new_group_values.push(row);
- }
- std::mem::swap(&mut new_group_values, &mut group_values);
-
- self.map.retain(|(_exists_hash, group_idx)| {
- // Decrement group index by n
- match group_idx.checked_sub(n) {
- // Group index was >= n, shift value down
- Some(sub) => {
- *group_idx = sub;
- true
- }
- // Group index was < n, so remove from table
- None => false,
+ if self.drain_mode {
+ let start = self.emission_offset;
+ let end = std::cmp::min(start + n,
group_values.num_rows());
+ let iter = group_values.iter().skip(start).take(end -
start);
+ let output = self.row_converter.convert_rows(iter)?;
+ self.emission_offset = end;
+ if self.emission_offset == group_values.num_rows() {
+ group_values.clear();
+ self.emission_offset = 0;
Review Comment:
Doesn't that mean then that the `else` part (when `drain_mode == false`) is
now dead code? FWIW I can put a `panic!()` here:
```rust
output
} else {
+ panic!("foo");
let groups_rows = group_values.iter().take(n);
let output =
self.row_converter.convert_rows(groups_rows)?;
```
And all the tests in the crate pass
--
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]