Skip to content

Commit 85fd064

Browse files
fix[mask]: intersect_by_rank and bit to arrow (#5545)
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 984b64f commit 85fd064

File tree

5 files changed

+30
-27
lines changed

5 files changed

+30
-27
lines changed

vortex-array/src/arrays/bool/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ impl FromIterator<Option<bool>> for BoolArray {
247247

248248
impl IntoArray for BitBuffer {
249249
fn into_array(self) -> ArrayRef {
250-
let len = self.len();
251-
BoolArray::try_new(self.into_inner(), 0, len, Validity::NonNullable)
250+
let (offset, len, buffer) = self.into_inner();
251+
BoolArray::try_new(buffer, offset, len, Validity::NonNullable)
252252
.vortex_expect("known correct")
253253
.into_array()
254254
}

vortex-buffer/src/bit/arrow.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ impl From<BooleanBuffer> for BitBuffer {
2222

2323
impl From<BitBuffer> for BooleanBuffer {
2424
fn from(value: BitBuffer) -> Self {
25-
let offset = value.offset();
26-
let len = value.len();
27-
let buffer = value.into_inner();
25+
let (offset, len, buffer) = value.into_inner();
2826

2927
BooleanBuffer::new(buffer.into_arrow_buffer(), offset, len)
3028
}

vortex-buffer/src/bit/buf.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::ops::BitAnd;
55
use std::ops::BitOr;
66
use std::ops::BitXor;
7+
use std::ops::Bound;
78
use std::ops::Not;
89
use std::ops::RangeBounds;
910

@@ -195,14 +196,14 @@ impl BitBuffer {
195196
/// Panics if the slice would extend beyond the end of the buffer.
196197
pub fn slice(&self, range: impl RangeBounds<usize>) -> Self {
197198
let start = match range.start_bound() {
198-
std::ops::Bound::Included(&s) => s,
199-
std::ops::Bound::Excluded(&s) => s + 1,
200-
std::ops::Bound::Unbounded => 0,
199+
Bound::Included(&s) => s,
200+
Bound::Excluded(&s) => s + 1,
201+
Bound::Unbounded => 0,
201202
};
202203
let end = match range.end_bound() {
203-
std::ops::Bound::Included(&e) => e + 1,
204-
std::ops::Bound::Excluded(&e) => e,
205-
std::ops::Bound::Unbounded => self.len,
204+
Bound::Included(&e) => e + 1,
205+
Bound::Excluded(&e) => e,
206+
Bound::Unbounded => self.len,
206207
};
207208

208209
assert!(start <= end);
@@ -215,9 +216,13 @@ impl BitBuffer {
215216

216217
/// Slice any full bytes from the buffer, leaving the offset < 8.
217218
pub fn shrink_offset(self) -> Self {
219+
let word_start = self.offset / 8;
220+
let word_end = (self.offset + self.len).div_ceil(8);
221+
222+
let buffer = self.buffer.slice(word_start..word_end);
223+
218224
let bit_offset = self.offset % 8;
219225
let len = self.len;
220-
let buffer = self.into_inner();
221226
BitBuffer::new_with_offset(buffer, len, bit_offset)
222227
}
223228

@@ -273,13 +278,9 @@ impl BitBuffer {
273278
// Conversions
274279

275280
impl BitBuffer {
276-
/// Consumes this `BoolBuffer` and returns the backing `Buffer<u8>` with any offset
277-
/// and length information applied.
278-
pub fn into_inner(self) -> ByteBuffer {
279-
let word_start = self.offset / 8;
280-
let word_end = (self.offset + self.len).div_ceil(8);
281-
282-
self.buffer.slice(word_start..word_end)
281+
/// Returns the offset, len and underlying buffer.
282+
pub fn into_inner(self) -> (usize, usize, ByteBuffer) {
283+
(self.offset, self.len, self.buffer)
283284
}
284285

285286
/// Attempt to convert this `BitBuffer` into a mutable version.
@@ -295,11 +296,9 @@ impl BitBuffer {
295296
/// If the caller doesn't hold only reference to the underlying buffer, a copy is created.
296297
/// The second value of the tuple is a bit_offset of the first value in the first byte
297298
pub fn into_mut(self) -> BitBufferMut {
298-
let offset = self.offset;
299-
let len = self.len;
299+
let (offset, len, inner) = self.into_inner();
300300
// TODO(robert): if we are copying here we could strip offset bits
301-
let inner = self.into_inner().into_mut();
302-
BitBufferMut::from_buffer(inner, offset, len)
301+
BitBufferMut::from_buffer(inner.into_mut(), offset, len)
303302
}
304303
}
305304

vortex-mask/src/intersect_by_rank.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl Mask {
3232
match (self.indices(), mask.indices()) {
3333
(AllOr::All, _) => mask.clone(),
3434
(_, AllOr::All) => self.clone(),
35-
(AllOr::None, _) => Self::new_false(0),
36-
(_, AllOr::None) => Self::new_false(self.len()),
35+
(AllOr::None, _) | (_, AllOr::None) => Self::new_false(self.len()),
36+
3737
(AllOr::Some(self_indices), AllOr::Some(mask_indices)) => {
3838
Self::from_indices(
3939
self.len(),
@@ -95,6 +95,13 @@ mod test {
9595
assert_eq!(this.intersect_by_rank(&mask), Mask::from_indices(5, vec![]));
9696
}
9797

98+
#[test]
99+
fn mask_intersect_by_rank_all_false() {
100+
let this = Mask::AllFalse(10);
101+
let mask = Mask::AllFalse(0);
102+
assert_eq!(this.intersect_by_rank(&mask), Mask::AllFalse(10));
103+
}
104+
98105
#[rstest]
99106
#[case::all_true_with_all_true(
100107
Mask::new_true(5),

vortex-vector/src/vector_ops.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! [`VectorMut`], respectively.
66
77
use std::fmt::Debug;
8+
use std::ops::Bound;
89
use std::ops::RangeBounds;
910

1011
use vortex_mask::Mask;
@@ -178,8 +179,6 @@ pub trait VectorMutOps: private::Sealed + Into<VectorMut> + Sized {
178179

179180
/// Converts a range bounds into a length, given the total length of the vector.
180181
pub(crate) fn range_bounds_to_len(bounds: impl RangeBounds<usize> + Debug, len: usize) -> usize {
181-
use std::ops::Bound;
182-
183182
let start = match bounds.start_bound() {
184183
Bound::Included(&s) => s,
185184
Bound::Excluded(&s) => s + 1,

0 commit comments

Comments
 (0)