Dandandan commented on code in PR #15591:
URL: https://github.com/apache/datafusion/pull/15591#discussion_r3080688241


##########
datafusion/functions-aggregate-common/src/aggregate/groups_accumulator/prim_op.rs:
##########
@@ -93,21 +94,31 @@ where
         opt_filter: Option<&BooleanArray>,
         total_num_groups: usize,
     ) -> Result<()> {
+        const DEFAULT_BLOCK_CAP: usize = 128;
+
         assert_eq!(values.len(), 1, "single argument to update_batch");
         let values = values[0].as_primitive::<T>();
 
-        // update values
-        self.values.resize(total_num_groups, self.starting_value);
+        // Expand to ensure values are large enough
+        let new_block = |block_size: Option<usize>| {
+            let cap = block_size.unwrap_or(DEFAULT_BLOCK_CAP);
+            Vec::with_capacity(cap)
+        };
+        self.values
+            .resize(total_num_groups, new_block, self.starting_value);
 
         // NullState dispatches / handles tracking nulls and groups that saw 
no values
         self.null_state.accumulate(
             group_indices,
             values,
             opt_filter,
             total_num_groups,
-            |group_index, new_value| {
-                // SAFETY: group_index is guaranteed to be in bounds
-                let value = unsafe { 
self.values.get_unchecked_mut(group_index) };
+            |block_id, block_offset, new_value| {
+                // SAFETY: `block_id` and `block_offset` are guaranteed to be 
in bounds
+                let value = unsafe {
+                    self.values[block_id as usize]

Review Comment:
   this can use unsafe index as well (with a plain `Vec` it would certainly be 
faster)



-- 
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]

Reply via email to