Skip to content

Commit

Permalink
Improve documenataion and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eejbyfeldt committed Aug 25, 2024
1 parent 1bf7b9b commit 0f1b64c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,9 @@ impl NullState {
/// * `opt_filter`: if present, only rows for which is Some(true) are included
/// * `value_fn`: function invoked for (group_index, value) where value is non null
///
/// # Example
/// See [`accumulate`], for more details on how value_fn is called
///
/// ```text
/// β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œ ─ ─ ─ ─ ┐
/// β”‚ β”Œβ”€β”€β”€β”€β”€β” β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β” β”‚ β”Œβ”€β”€β”€β”€β”€β”
/// β”‚ β”‚ 2 β”‚ β”‚ β”‚ β”‚ 200 β”‚ β”‚ β”‚ β”‚ t β”‚ β”‚
/// β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”œβ”€β”€β”€β”€β”€β”€
/// β”‚ β”‚ 2 β”‚ β”‚ β”‚ β”‚ 100 β”‚ β”‚ β”‚ β”‚ f β”‚ β”‚
/// β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”œβ”€β”€β”€β”€β”€β”€
/// β”‚ β”‚ 0 β”‚ β”‚ β”‚ β”‚ 200 β”‚ β”‚ β”‚ β”‚ t β”‚ β”‚
/// β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”œβ”€β”€β”€β”€β”€β”€
/// β”‚ β”‚ 1 β”‚ β”‚ β”‚ β”‚ 200 β”‚ β”‚ β”‚ β”‚NULL β”‚ β”‚
/// β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”œβ”€β”€β”€β”€β”€β”€
/// β”‚ β”‚ 0 β”‚ β”‚ β”‚ β”‚ 300 β”‚ β”‚ β”‚ β”‚ t β”‚ β”‚
/// β”‚ β””β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”˜
/// β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”” ─ ─ ─ ─ β”˜
///
/// group_indices values opt_filter
/// ```
///
/// In the example above, `value_fn` is invoked for each (group_index,
/// value) pair where `opt_filter[i]` is true and values is non null
///
/// ```text
/// value_fn(2, 200)
/// value_fn(0, 200)
/// value_fn(0, 300)
/// ```
///
/// It also sets
/// When value_fn is called it also sets
///
/// 1. `self.seen_values[group_index]` to true for all rows that had a non null vale
pub fn accumulate<T, F>(
Expand Down Expand Up @@ -260,6 +233,44 @@ impl NullState {
}
}

/// Invokes `value_fn(group_index, value)` for each non null, non

This comment has been minimized.

Copy link
@alamb

alamb Aug 25, 2024

Contributor

πŸ‘

/// filtered value of `value`,
///
/// # Arguments:
///
/// * `group_indices`: To which groups do the rows in `values` belong, (aka group_index)
/// * `values`: the input arguments to the accumulator
/// * `opt_filter`: if present, only rows for which is Some(true) are included
/// * `value_fn`: function invoked for (group_index, value) where value is non null
///
/// # Example
///
/// ```text
/// β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œ ─ ─ ─ ─ ┐
/// β”‚ β”Œβ”€β”€β”€β”€β”€β” β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β” β”‚ β”Œβ”€β”€β”€β”€β”€β”
/// β”‚ β”‚ 2 β”‚ β”‚ β”‚ β”‚ 200 β”‚ β”‚ β”‚ β”‚ t β”‚ β”‚
/// β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”œβ”€β”€β”€β”€β”€β”€
/// β”‚ β”‚ 2 β”‚ β”‚ β”‚ β”‚ 100 β”‚ β”‚ β”‚ β”‚ f β”‚ β”‚
/// β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”œβ”€β”€β”€β”€β”€β”€
/// β”‚ β”‚ 0 β”‚ β”‚ β”‚ β”‚ 200 β”‚ β”‚ β”‚ β”‚ t β”‚ β”‚
/// β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”œβ”€β”€β”€β”€β”€β”€
/// β”‚ β”‚ 1 β”‚ β”‚ β”‚ β”‚ 200 β”‚ β”‚ β”‚ β”‚NULL β”‚ β”‚
/// β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€ β”‚ β”œβ”€β”€β”€β”€β”€β”€
/// β”‚ β”‚ 0 β”‚ β”‚ β”‚ β”‚ 300 β”‚ β”‚ β”‚ β”‚ t β”‚ β”‚
/// β”‚ β””β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”˜
/// β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”” ─ ─ ─ ─ β”˜
///
/// group_indices values opt_filter
/// ```
///
/// In the example above, `value_fn` is invoked for each (group_index,
/// value) pair where `opt_filter[i]` is true and values is non null
///
/// ```text
/// value_fn(2, 200)
/// value_fn(0, 200)
/// value_fn(0, 300)
/// ```
pub fn accumulate<T, F>(
group_indices: &[usize],
values: &PrimitiveArray<T>,
Expand Down
4 changes: 3 additions & 1 deletion datafusion/functions-aggregate/src/variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ impl VarianceGroupsAccumulator {
emit_to: datafusion_expr::EmitTo,
) -> (Vec<f64>, NullBuffer) {
let mut counts = emit_to.take_needed(&mut self.counts);
// means are only needed for updating m2s and are not needed for the final result.
// But we still need to take them to ensure the internal state is consistent.
let _ = emit_to.take_needed(&mut self.means);
let m2s = emit_to.take_needed(&mut self.m2s);

Expand Down Expand Up @@ -517,7 +519,7 @@ impl GroupsAccumulator for VarianceGroupsAccumulator {
total_num_groups: usize,
) -> Result<()> {
assert_eq!(values.len(), 3, "two arguments to merge_batch");
// first batch is counts, second is partial sums
// first batch is counts, second is partial means, third is partial m2s
let partial_counts = downcast_value!(values[0], UInt64Array);
let partial_means = downcast_value!(values[1], Float64Array);
let partial_m2s = downcast_value!(values[2], Float64Array);
Expand Down

0 comments on commit 0f1b64c

Please sign in to comment.