Skip to content

Commit ee67d80

Browse files
blagininclaude
andcommitted
validity cleanup
Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: blaginin <dima@spiraldb.com>
1 parent 6bafabe commit ee67d80

1 file changed

Lines changed: 8 additions & 19 deletions

File tree

  • vortex-array/src/aggregate_fn/fns/mean

vortex-array/src/aggregate_fn/fns/mean/mod.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,14 @@ impl AggregateFnVTable for Mean {
220220
.map(|(s, c)| if *c == 0 { 0.0 } else { s / *c as f64 })
221221
.collect();
222222

223-
let validity = match validity_mask {
224-
Mask::AllTrue(_) => {
225-
let valid_bits: Vec<bool> = count_values.iter().map(|c| *c > 0).collect();
226-
if valid_bits.iter().all(|v| *v) {
227-
Validity::AllValid
228-
} else {
229-
Validity::from_iter(valid_bits)
230-
}
231-
}
232-
Mask::AllFalse(_) => Validity::AllInvalid,
233-
Mask::Values(v) => {
234-
let valid_bits: Vec<bool> = count_values
235-
.iter()
236-
.zip(v.bit_buffer().iter())
237-
.map(|(c, group_valid)| group_valid && *c > 0)
238-
.collect();
239-
Validity::from_iter(valid_bits)
240-
}
241-
};
223+
// A mean is valid when the group itself was valid AND had at least one
224+
// non-null element (count > 0).
225+
let validity = Validity::from_iter(
226+
count_values
227+
.iter()
228+
.enumerate()
229+
.map(|(i, c)| validity_mask.value(i) && *c > 0),
230+
);
242231

243232
Ok(PrimitiveArray::new(means, validity).into_array())
244233
}

0 commit comments

Comments
 (0)