alamb commented on code in PR #25605:
URL: https://github.com/apache/datafusion/pull/25605#discussion_r4086586530
##########
datafusion/functions-aggregate-common/src/aggregate/groups_accumulator.rs:
##########
@@ -277,13 +377,20 @@ impl GroupsAccumulatorAdapter {
offset_so_far += indices.len();
offsets.push(offset_so_far);
}
- let batch_indices = batch_indices.into();
+ // Move the buffer into an array without a copy, for the take kernels
+ let indices_array =
+ PrimitiveArray::<UInt32Type>::from(std::mem::take(batch_indices));
// reorder the values and opt_filter by batch_indices so that
// all values for each group are contiguous, then invoke the
// accumulator once per group with values
- let values = take_arrays(values, &batch_indices, None)?;
- let opt_filter = get_filter_at_indices(opt_filter, &batch_indices)?;
+ let values = take_arrays(values, &indices_array, None)?;
+ let opt_filter = get_filter_at_indices(opt_filter, &indices_array)?;
+
+ // The take kernels only borrow the indices, so the array holds the
+ // only reference to the buffer and we can get it back without a copy
+ let (_, indices_buffer, _) = indices_array.into_parts();
+ *batch_indices =
indices_buffer.into_inner().into_vec().unwrap_or_default();
Review Comment:
so fancy
--
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]