comphead commented on code in PR #7801:
URL: https://github.com/apache/datafusion-comet/pull/7801#discussion_r4762659413
##########
native/spark-expr/src/agg_funcs/avg.rs:
##########
@@ -284,19 +284,25 @@ where
// first batch is partial sums, second is counts
let partial_sums = values[0].as_primitive::<T>();
let partial_counts = values[1].as_primitive::<Int64Type>();
- // update counts with partial counts
self.counts.resize(total_num_groups, 0);
- let iter1 = group_indices.iter().zip(partial_counts.values().iter());
- for (&group_index, &partial_count) in iter1 {
- self.counts[group_index] += partial_count;
+ self.sums.resize(total_num_groups, T::default_value());
+
+ let counts = partial_counts.values();
+ let sums = partial_sums.values();
+ for ((&group, &count), &value) in
group_indices.iter().zip(counts).zip(sums) {
+ self.counts[group] += count;
+ self.sums[group] = self.sums[group].add_wrapping(value);
}
- // update sums - no overflow checking (in all eval modes)
- self.sums.resize(total_num_groups, T::default_value());
- let iter2 = group_indices.iter().zip(partial_sums.values().iter());
- for (&group_index, &new_value) in iter2 {
- let sum = &mut self.sums[group_index];
- *sum = sum.add_wrapping(new_value);
+ // Preserve the independent zip lengths for uneven partial columns.
Review Comment:
This block and `merge_uneven_partial_columns` only reproduce an artifact of
the old two separate zips. `values[0]` and `values[1]` come from one
`RecordBatch`, so both columns and `group_indices` have the same length and the
two columns cannot differ in practice. Dropping the block (lines 297 to 306)
and the test keeps the single zip loop and removes about 25 lines of code that
never runs. If a length check is wanted, a `debug_assert_eq!(counts.len(),
sums.len())` says it more directly.
--
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]