diff --git a/src/array/primitive/mutable.rs b/src/array/primitive/mutable.rs index 4432ab2e33..9f71e066fc 100644 --- a/src/array/primitive/mutable.rs +++ b/src/array/primitive/mutable.rs @@ -93,6 +93,20 @@ impl MutablePrimitiveArray { pub fn apply_values(&mut self, f: F) { f(&mut self.values); } + + /// The number of null slots on this [`Array`]. + /// # Implementation + /// This is `O(1)` since the number of null elements is pre-computed. + #[inline] + pub fn null_count(&self) -> usize { + if self.data_type() == &DataType::Null { + return self.len(); + }; + self.validity() + .as_ref() + .map(|x| x.unset_bits()) + .unwrap_or(0) + } } impl Default for MutablePrimitiveArray {