From abb9eaa119a722aca42bd0697ce5d63d2c801915 Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Fri, 9 Aug 2024 11:28:20 +0100 Subject: [PATCH] Remove to_present_null_buffer from LogicalValidity (#579) --- .../src/array/primitive/compute/compare.rs | 14 +++++++++----- .../src/array/primitive/compute/filter_indices.rs | 9 ++++++--- vortex-array/src/validity.rs | 8 -------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/vortex-array/src/array/primitive/compute/compare.rs b/vortex-array/src/array/primitive/compute/compare.rs index 4e9123167..240754ba8 100644 --- a/vortex-array/src/array/primitive/compute/compare.rs +++ b/vortex-array/src/array/primitive/compute/compare.rs @@ -22,15 +22,19 @@ impl CompareFn for PrimitiveArray { let present = self .validity() .to_logical(self.len()) - .to_present_null_buffer()? - .into_inner(); + .to_null_buffer()? + .map(|b| b.into_inner()); let present_other = flattened .validity() .to_logical(self.len()) - .to_present_null_buffer()? - .into_inner(); + .to_null_buffer()? + .map(|b| b.into_inner()); - Ok(BoolArray::from(matching_idxs.bitand(&present).bitand(&present_other)).into_array()) + let mut result = matching_idxs; + result = present.map(|p| p.bitand(&result)).unwrap_or(result); + result = present_other.map(|p| p.bitand(&result)).unwrap_or(result); + + Ok(BoolArray::from(result).into_array()) } } diff --git a/vortex-array/src/array/primitive/compute/filter_indices.rs b/vortex-array/src/array/primitive/compute/filter_indices.rs index 55e31fbe3..dc44991d6 100644 --- a/vortex-array/src/array/primitive/compute/filter_indices.rs +++ b/vortex-array/src/array/primitive/compute/filter_indices.rs @@ -21,12 +21,15 @@ impl FilterIndicesFn for PrimitiveArray { let present_buf = self .validity() .to_logical(self.len()) - .to_present_null_buffer()? - .into_inner(); + .to_null_buffer()? + .map(|b| b.into_inner()); let bitset: VortexResult = conjunction_indices .reduce(|a, b| Ok(a?.bitor(&b?))) - .map(|bitset| Ok(bitset?.bitand(&present_buf))) + .map(|bitset| { + let bs = bitset?; + Ok(present_buf.map(|b| b.bitand(&bs)).unwrap_or(bs)) + }) .unwrap_or_else(|| Ok(BooleanBuffer::new_set(self.len()))); Ok(BoolArray::from(bitset?).into_array()) diff --git a/vortex-array/src/validity.rs b/vortex-array/src/validity.rs index b6157995d..05185e38b 100644 --- a/vortex-array/src/validity.rs +++ b/vortex-array/src/validity.rs @@ -238,14 +238,6 @@ impl LogicalValidity { } } - pub fn to_present_null_buffer(&self) -> VortexResult { - match self { - Self::AllValid(l) => Ok(NullBuffer::new_valid(*l)), - Self::AllInvalid(l) => Ok(NullBuffer::new_null(*l)), - Self::Array(a) => Ok(NullBuffer::new(a.clone().into_bool()?.boolean_buffer())), - } - } - pub fn all_valid(&self) -> bool { matches!(self, Self::AllValid(_)) }