Skip to content

Commit dacbb25

Browse files
fix[array]: validity mask into nullable (#5171)
Signed-off-by: Joe Isaacs <[email protected]>
1 parent c38ed37 commit dacbb25

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

vortex-array/src/validity.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Array validity and nullability behavior, used by arrays and compute functions.
55
66
use std::fmt::Debug;
7-
use std::ops::{BitAnd, Not, Range};
7+
use std::ops::{BitAnd, Range};
88

99
use vortex_buffer::BitBuffer;
1010
use vortex_dtype::{DType, Nullability};
@@ -180,16 +180,15 @@ impl Validity {
180180
pub fn mask(&self, mask: &Mask) -> Self {
181181
match mask.bit_buffer() {
182182
AllOr::All => Validity::AllInvalid,
183-
AllOr::None => self.clone(),
183+
AllOr::None => self.clone().into_nullable(),
184184
AllOr::Some(make_invalid) => match self {
185185
Validity::NonNullable | Validity::AllValid => {
186-
Validity::Array(BoolArray::from(make_invalid.not()).into_array())
186+
Validity::Array(BoolArray::from(!make_invalid).into_array())
187187
}
188188
Validity::AllInvalid => Validity::AllInvalid,
189189
Validity::Array(is_valid) => {
190190
let is_valid = is_valid.to_bool();
191-
let keep_valid = make_invalid.not();
192-
Validity::from(is_valid.bit_buffer() & &keep_valid)
191+
Validity::from(is_valid.bit_buffer() & !make_invalid)
193192
}
194193
},
195194
}
@@ -552,4 +551,12 @@ mod tests {
552551
) {
553552
assert_eq!(validity.take(&indices).unwrap(), expected);
554553
}
554+
555+
#[test]
556+
fn mask_non_nullable() {
557+
assert_eq!(
558+
Validity::AllValid,
559+
Validity::NonNullable.mask(&Mask::AllFalse(2))
560+
)
561+
}
555562
}

vortex-buffer/src/bit/buf.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@ impl BitAnd for &BitBuffer {
338338
}
339339
}
340340

341+
impl BitAnd<BitBuffer> for &BitBuffer {
342+
type Output = BitBuffer;
343+
344+
fn bitand(self, rhs: BitBuffer) -> Self::Output {
345+
self.bitand(&rhs)
346+
}
347+
}
348+
341349
impl BitAnd<&BitBuffer> for BitBuffer {
342350
type Output = BitBuffer;
343351

0 commit comments

Comments
 (0)