Dandandan commented on code in PR #22712:
URL: https://github.com/apache/datafusion/pull/22712#discussion_r3340347710
##########
datafusion/functions-aggregate/src/average.rs:
##########
@@ -970,7 +1130,262 @@ where
true
}
+ fn create_blocked_accumulator(
+ &self,
+ block_size: usize,
+ ) -> Result<Option<Box<dyn GroupsAccumulator>>> {
+ if self.sum_data_type == DataType::Float64
+ && self.return_data_type == DataType::Float64
+ {
+ Ok(Some(Box::new(BlockedAvgGroupsAccumulator::new(block_size))))
+ } else {
+ Ok(None)
+ }
+ }
+
fn size(&self) -> usize {
self.counts.capacity() * size_of::<u64>() + self.sums.capacity() *
size_of::<T>()
}
}
+
+impl GroupsAccumulator for BlockedAvgGroupsAccumulator {
+ fn update_batch(
+ &mut self,
+ values: &[ArrayRef],
+ group_indices: &[usize],
+ opt_filter: Option<&BooleanArray>,
+ total_num_groups: usize,
+ ) -> Result<()> {
+ assert_eq!(values.len(), 1, "single argument to update_batch");
+ let values = values[0].as_primitive::<Float64Type>();
+ self.ensure_capacity(total_num_groups);
+
+ let counts = &mut self.counts;
+ let sums = &mut self.sums;
+ let block_size = self.block_size;
+ let len = self.len;
+
+ self.null_state.accumulate(
+ group_indices,
+ values,
+ opt_filter,
+ total_num_groups,
+ |group_index, value| {
+ debug_assert!(group_index < len);
+ let block_idx = group_index / block_size;
+ let value_idx = group_index % block_size;
Review Comment:
I think you want to avoid `%` and `/` (two integer divisions!) by enforcing
power of two.
--
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]