diff --git a/vortex-array/src/array/primitive/compute/compare.rs b/vortex-array/src/array/primitive/compute/compare.rs index 4e91231672..240754ba8f 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 55e31fbe3e..dc44991d68 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 b6157995d3..05185e38bd 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(_)) }