lkt commented on code in PR #10149:
URL: https://github.com/apache/datafusion/pull/10149#discussion_r1579262396


##########
datafusion/physical-expr/src/aggregate/array_agg.rs:
##########
@@ -187,17 +333,261 @@ impl Accumulator for ArrayAggAccumulator {
     }
 }
 
+struct ArrayAggGroupsAccumulator<T>
+where
+    T: ArrowPrimitiveType + Send,
+{
+    values: Vec<PrimitiveBuilder<T>>,
+    data_type: DataType,
+    null_state: NullState,
+}
+
+impl<T> ArrayAggGroupsAccumulator<T>
+where
+    T: ArrowPrimitiveType + Send,
+{
+    pub fn new(data_type: &DataType) -> Self {
+        Self {
+            values: vec![],
+            data_type: data_type.clone(),
+            null_state: NullState::new(),
+        }
+    }
+}
+
+impl<T: ArrowPrimitiveType + Send> ArrayAggGroupsAccumulator<T> {
+    fn build_list(&mut self, emit_to: EmitTo) -> Result<ArrayRef> {
+        let arrays = emit_to.take_needed(&mut self.values);
+        let nulls = self.null_state.build(emit_to);
+
+        let len = nulls.len();
+        assert_eq!(arrays.len(), len);
+
+        let mut builder = ListBuilder::with_capacity(
+            
PrimitiveBuilder::<T>::new().with_data_type(self.data_type.clone()),
+            len,
+        );
+
+        for (is_valid, mut arr) in nulls.iter().zip(arrays.into_iter()) {
+            if is_valid {
+                builder.append_value(arr.finish().into_iter());
+            } else {
+                builder.append_null();
+            }
+        }
+
+        Ok(Arc::new(builder.finish()))
+    }
+}
+
+impl<T> GroupsAccumulator for ArrayAggGroupsAccumulator<T>
+where
+    T: ArrowPrimitiveType + Send + Sync,
+{
+    fn update_batch(
+        &mut self,
+        new_values: &[ArrayRef],
+        group_indices: &[usize],
+        opt_filter: Option<&BooleanArray>,
+        total_num_groups: usize,
+    ) -> Result<()> {
+        assert_eq!(new_values.len(), 1, "single argument to update_batch");

Review Comment:
   Thanks for your suggestion. I would keep the `assert_eq!` here to keep it 
consistent with other implementations of `GroupsAccumulator`. Eg. see here 
among others:
   
https://github.com/apache/datafusion/blob/main/datafusion/physical-expr/src/aggregate/groups_accumulator/prim_op.rs?plain=1#L93
   
   Also this assertion is meant for developer to ensure the correct number of 
elements in the array between aggregation stages, not the end user. Let me know 
what you think.



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