comphead commented on code in PR #10149:
URL: https://github.com/apache/datafusion/pull/10149#discussion_r1579643886
##########
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:
We prefer to get rid of application crashes, returning error instead of
panic will help. But thanks for pointing out we may want to revisit assertions
and return errors wherever possible
--
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]