Skip to content

Commit 421b6d4

Browse files
committed
fixes
Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent f8715f6 commit 421b6d4

16 files changed

Lines changed: 1 addition & 377 deletions

File tree

‎vortex-array/src/arrays/varbin/builder.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,6 @@ impl<O: OffsetBuilderPType> ArrayBuilder for VarBinBuilder<O> {
630630
self.validity.reserve(additional);
631631
}
632632

633-
unsafe fn set_validity_unchecked(&mut self, validity: Mask) {
634-
self.replace_validity(validity)
635-
}
636-
637633
fn finish(&mut self) -> ArrayRef {
638634
self.finish_into_varbin().into_array()
639635
}
@@ -949,7 +945,6 @@ mod tests {
949945
builder.append_scalar(&Scalar::utf8("hello", Nullable))?;
950946
builder.append_null();
951947
assert_eq!(builder.len(), 3);
952-
builder.set_validity(validity.clone());
953948
Ok(())
954949
})?;
955950
assert_eq!(result.validity()?.execute_mask(3, &mut ctx)?, validity);

‎vortex-array/src/builders/bool.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::mem;
77
use vortex_buffer::BitBufferMut;
88
use vortex_error::VortexResult;
99
use vortex_error::vortex_ensure;
10-
use vortex_mask::Mask;
1110

1211
use crate::ArrayRef;
1312
use crate::ExecutionCtx;
@@ -127,10 +126,6 @@ impl ArrayBuilder for BoolBuilder {
127126
self.nulls.reserve_exact(additional);
128127
}
129128

130-
unsafe fn set_validity_unchecked(&mut self, validity: Mask) {
131-
self.nulls = LazyBitBufferBuilder::from_validity_mask(validity);
132-
}
133-
134129
fn finish(&mut self) -> ArrayRef {
135130
self.finish_into_bool().into_array()
136131
}

‎vortex-array/src/builders/child.rs‎

Lines changed: 1 addition & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use vortex_error::VortexExpect;
54
use vortex_error::VortexResult;
65
use vortex_error::vortex_ensure;
7-
use vortex_mask::Mask;
86

97
use crate::ArrayRef;
108
use crate::ExecutionCtx;
119
use crate::IntoArray;
1210
use crate::arrays::ChunkedArray;
13-
use crate::arrays::MaskedArray;
1411
use crate::builders::ArrayBuilder;
1512
use crate::builders::builder_with_capacity;
1613
use crate::dtype::DType;
17-
use crate::dtype::Nullability;
1814
use crate::scalar::Scalar;
19-
use crate::validity::Validity;
2015

2116
/// Accumulates the child of a nested [`ArrayBuilder`] without canonicalizing appended arrays.
2217
///
@@ -121,42 +116,6 @@ impl ChildBuilder {
121116
self.pending.reserve_exact(additional)
122117
}
123118

124-
/// Overrides the validity of every value appended so far.
125-
///
126-
/// # Safety
127-
///
128-
/// `validity` must have the same length as [`self.len()`](Self::len).
129-
///
130-
/// # Panics
131-
///
132-
/// Panics if a chunk that was kept in its original encoding contains nulls, since replacing
133-
/// the validity of such a chunk would require decoding it.
134-
pub unsafe fn set_validity_unchecked(&mut self, validity: Mask) {
135-
if !self.dtype.is_nullable() {
136-
return;
137-
}
138-
139-
if self.chunks.is_empty() {
140-
// Fast path: every value lives in the scalar builder, which owns its null buffer.
141-
unsafe { self.pending.set_validity_unchecked(validity) };
142-
return;
143-
}
144-
145-
// The chunks carry their own validity, so the override has to be pushed into each of them.
146-
self.flush_pending();
147-
let mut offset = 0;
148-
for chunk in &mut self.chunks {
149-
let end = offset + chunk.len();
150-
*chunk = MaskedArray::try_new(
151-
chunk.clone(),
152-
Validity::from_mask(validity.slice(offset..end), Nullability::Nullable),
153-
)
154-
.vortex_expect("cannot override the validity of a child chunk that contains nulls")
155-
.into_array();
156-
offset = end;
157-
}
158-
}
159-
160119
/// Finishes the child, combining the accumulated chunks into a [`ChunkedArray`] when there is
161120
/// more than one of them.
162121
pub fn finish(&mut self) -> ArrayRef {
@@ -172,9 +131,7 @@ impl ChildBuilder {
172131
return chunks.remove(0);
173132
}
174133

175-
ChunkedArray::try_new(chunks, self.dtype.clone())
176-
.vortex_expect("every child chunk has the child dtype")
177-
.into_array()
134+
unsafe { ChunkedArray::new_unchecked(chunks, self.dtype.clone()) }.into_array()
178135
}
179136

180137
/// Moves whatever the scalar builder holds into `chunks`, keeping the chunks in logical order.
@@ -192,9 +149,7 @@ impl ChildBuilder {
192149
mod tests {
193150
use rstest::rstest;
194151
use vortex_buffer::buffer;
195-
use vortex_error::VortexExpect;
196152
use vortex_error::VortexResult;
197-
use vortex_mask::Mask;
198153

199154
use super::ChildBuilder;
200155
use crate::ArrayRef;
@@ -205,7 +160,6 @@ mod tests {
205160
use crate::arrays::ChunkedArray;
206161
use crate::arrays::Constant;
207162
use crate::arrays::ConstantArray;
208-
use crate::arrays::Masked;
209163
use crate::arrays::Primitive;
210164
use crate::arrays::PrimitiveArray;
211165
use crate::arrays::chunked::ChunkedArrayExt;
@@ -380,104 +334,6 @@ mod tests {
380334
Ok(())
381335
}
382336

383-
/// Overriding the validity once chunks exist has to push the override into each chunk, sliced
384-
/// to that chunk's own range.
385-
#[test]
386-
fn test_set_validity_pushes_the_override_into_every_chunk() -> VortexResult<()> {
387-
let mut ctx = array_session().create_execution_ctx();
388-
let dtype = DType::Primitive(I32, Nullable);
389-
let mut builder = ChildBuilder::with_capacity(&dtype, 0);
390-
391-
builder.append_array(&nullable_constant(1, CHUNK_LEN), &mut ctx)?;
392-
builder.append_array(&nullable_constant(2, CHUNK_LEN), &mut ctx)?;
393-
394-
// Straddle the chunk boundary, so an override sliced wrongly cannot pass.
395-
let invalid = [CHUNK_LEN - 1, CHUNK_LEN];
396-
let validity = Mask::from_iter((0..2 * CHUNK_LEN).map(|i| !invalid.contains(&i)));
397-
unsafe { builder.set_validity_unchecked(validity) };
398-
399-
let child = builder.finish();
400-
let chunked = child.as_::<Chunked>();
401-
assert_eq!(chunked.nchunks(), 2);
402-
// The override was layered over the chunks rather than decoding them.
403-
assert!(chunked.iter_chunks().all(|chunk| chunk.is::<Masked>()));
404-
405-
let expected = PrimitiveArray::from_option_iter(
406-
(0..2 * CHUNK_LEN)
407-
.map(|i| (!invalid.contains(&i)).then_some(if i < CHUNK_LEN { 1i32 } else { 2 })),
408-
)
409-
.into_array();
410-
assert_arrays_eq!(&child, &expected, &mut ctx);
411-
412-
Ok(())
413-
}
414-
415-
/// Values still sitting in the scalar builder are part of the override too.
416-
#[test]
417-
fn test_set_validity_covers_pending_scalars() -> VortexResult<()> {
418-
let mut ctx = array_session().create_execution_ctx();
419-
let dtype = DType::Primitive(I32, Nullable);
420-
let mut builder = ChildBuilder::with_capacity(&dtype, 0);
421-
422-
builder.append_array(&nullable_constant(1, CHUNK_LEN), &mut ctx)?;
423-
builder.append_scalar(&Scalar::primitive(2i32, Nullable))?;
424-
425-
let mut validity = vec![true; CHUNK_LEN + 1];
426-
validity[CHUNK_LEN] = false;
427-
unsafe { builder.set_validity_unchecked(Mask::from_iter(validity)) };
428-
429-
let child = builder.finish();
430-
let expected = PrimitiveArray::from_option_iter(
431-
std::iter::repeat_n(Some(1i32), CHUNK_LEN).chain([None]),
432-
)
433-
.into_array();
434-
assert_arrays_eq!(&child, &expected, &mut ctx);
435-
436-
Ok(())
437-
}
438-
439-
/// A non-nullable child cannot carry nulls, so the override is dropped and the chunks are left
440-
/// exactly as they were appended.
441-
#[test]
442-
fn test_set_validity_is_a_noop_for_a_non_nullable_child() -> VortexResult<()> {
443-
let mut ctx = array_session().create_execution_ctx();
444-
let mut builder = ChildBuilder::with_capacity(&DType::from(I32), 0);
445-
446-
builder.append_array(&constant(1, CHUNK_LEN), &mut ctx)?;
447-
builder.append_array(&constant(2, CHUNK_LEN), &mut ctx)?;
448-
unsafe { builder.set_validity_unchecked(Mask::new_false(2 * CHUNK_LEN)) };
449-
450-
let child = builder.finish();
451-
let chunked = child.as_::<Chunked>();
452-
assert!(chunked.iter_chunks().all(|chunk| chunk.is::<Constant>()));
453-
454-
let expected = ChunkedArray::try_new(
455-
vec![constant(1, CHUNK_LEN), constant(2, CHUNK_LEN)],
456-
DType::from(I32),
457-
)?
458-
.into_array();
459-
assert_arrays_eq!(&child, &expected, &mut ctx);
460-
461-
Ok(())
462-
}
463-
464-
/// Replacing the validity of a chunk that already contains nulls would mean decoding it, which
465-
/// is exactly what the chunk exists to avoid.
466-
#[test]
467-
#[should_panic(expected = "cannot override the validity of a child chunk that contains nulls")]
468-
fn test_set_validity_rejects_a_chunk_that_contains_nulls() {
469-
let mut ctx = array_session().create_execution_ctx();
470-
let dtype = DType::Primitive(I32, Nullable);
471-
let mut builder = ChildBuilder::with_capacity(&dtype, 0);
472-
473-
let with_nulls = ConstantArray::new(Scalar::null(dtype), CHUNK_LEN).into_array();
474-
builder
475-
.append_array(&with_nulls, &mut ctx)
476-
.vortex_expect("append");
477-
478-
unsafe { builder.set_validity_unchecked(Mask::new_true(CHUNK_LEN)) };
479-
}
480-
481337
#[test]
482338
fn test_finish_resets_the_builder() -> VortexResult<()> {
483339
let mut ctx = array_session().create_execution_ctx();

‎vortex-array/src/builders/decimal.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use vortex_error::VortexResult;
99
use vortex_error::vortex_ensure;
1010
use vortex_error::vortex_err;
1111
use vortex_error::vortex_panic;
12-
use vortex_mask::Mask;
1312

1413
use crate::ArrayRef;
1514
use crate::ExecutionCtx;
@@ -219,10 +218,6 @@ impl ArrayBuilder for DecimalBuilder {
219218
self.nulls.reserve_exact(additional);
220219
}
221220

222-
unsafe fn set_validity_unchecked(&mut self, validity: Mask) {
223-
self.nulls = LazyBitBufferBuilder::from_validity_mask(validity);
224-
}
225-
226221
fn finish(&mut self) -> ArrayRef {
227222
self.finish_into_decimal().into_array()
228223
}

‎vortex-array/src/builders/extension.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::any::Any;
55

66
use vortex_error::VortexResult;
77
use vortex_error::vortex_ensure;
8-
use vortex_mask::Mask;
98

109
use crate::ArrayRef;
1110
use crate::ExecutionCtx;
@@ -114,10 +113,6 @@ impl ArrayBuilder for ExtensionBuilder {
114113
self.storage.reserve_exact(capacity)
115114
}
116115

117-
unsafe fn set_validity_unchecked(&mut self, validity: Mask) {
118-
unsafe { self.storage.set_validity_unchecked(validity) };
119-
}
120-
121116
fn finish(&mut self) -> ArrayRef {
122117
self.finish_into_extension().into_array()
123118
}

‎vortex-array/src/builders/fixed_size_list.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use vortex_error::VortexResult;
99
use vortex_error::vortex_bail;
1010
use vortex_error::vortex_ensure;
1111
use vortex_error::vortex_panic;
12-
use vortex_mask::Mask;
1312

1413
use crate::ArrayRef;
1514
use crate::ExecutionCtx;
@@ -260,10 +259,6 @@ impl ArrayBuilder for FixedSizeListBuilder {
260259
self.nulls.reserve_exact(additional);
261260
}
262261

263-
unsafe fn set_validity_unchecked(&mut self, validity: Mask) {
264-
self.nulls.set_validity(validity);
265-
}
266-
267262
fn finish(&mut self) -> ArrayRef {
268263
self.finish_into_fixed_size_list().into_array()
269264
}

‎vortex-array/src/builders/lazy_null_builder.rs‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,6 @@ impl LazyBitBufferBuilder {
3131
}
3232
}
3333

34-
/// Creates a builder pre-populated from a validity mask, taking ownership of the mask's buffer
35-
/// instead of copying it where possible.
36-
///
37-
/// This is the counterpart to [`append_validity_mask`](Self::append_validity_mask) for callers
38-
/// that want to *replace* the builder's contents with the mask rather than extend them: because
39-
/// we own the mask, we can move its buffer in instead of copying it.
40-
pub fn from_validity_mask(validity_mask: Mask) -> Self {
41-
match validity_mask {
42-
// An unmaterialized builder already represents `len` non-null values, so an all-valid
43-
// mask stays lazy.
44-
Mask::AllTrue(len) => Self {
45-
inner: None,
46-
len,
47-
capacity: len,
48-
},
49-
Mask::AllFalse(len) => Self::from_buffer(BitBufferMut::new_unset(len)),
50-
// Take ownership of the underlying buffer; `into_bit_buffer` and `try_into_mut` only
51-
// copy when the buffer is shared, otherwise this is a move.
52-
values @ Mask::Values(_) => Self::from_buffer(
53-
values
54-
.into_bit_buffer()
55-
.try_into_mut()
56-
.unwrap_or_else(|buffer| BitBufferMut::copy_from(&buffer)),
57-
),
58-
}
59-
}
60-
61-
/// Creates a builder backed by an already-materialized buffer.
62-
fn from_buffer(inner: BitBufferMut) -> Self {
63-
Self {
64-
inner: Some(inner),
65-
len: 0,
66-
capacity: 0,
67-
}
68-
}
69-
7034
/// Appends `n` non-null values to the builder.
7135
#[inline]
7236
pub fn append_n_non_nulls(&mut self, n: usize) {

‎vortex-array/src/builders/list.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use vortex_error::VortexResult;
1010
use vortex_error::vortex_bail;
1111
use vortex_error::vortex_ensure;
1212
use vortex_error::vortex_panic;
13-
use vortex_mask::Mask;
1413

1514
use crate::ArrayRef;
1615
use crate::Canonical;
@@ -377,10 +376,6 @@ impl<O: OffsetBuilderPType> ArrayBuilder for ListBuilder<O> {
377376
self.nulls.reserve_exact(additional);
378377
}
379378

380-
unsafe fn set_validity_unchecked(&mut self, validity: Mask) {
381-
self.nulls.set_validity(validity);
382-
}
383-
384379
fn finish(&mut self) -> ArrayRef {
385380
self.finish_into_list().into_array()
386381
}

‎vortex-array/src/builders/listview.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use vortex_error::VortexExpect;
1616
use vortex_error::VortexResult;
1717
use vortex_error::vortex_ensure;
1818
use vortex_error::vortex_panic;
19-
use vortex_mask::Mask;
2019

2120
use crate::ArrayRef;
2221
use crate::Canonical;
@@ -416,10 +415,6 @@ impl<O: OffsetBuilderPType, S: OffsetBuilderPType> ArrayBuilder for ListViewBuil
416415
self.nulls.reserve_exact(capacity);
417416
}
418417

419-
unsafe fn set_validity_unchecked(&mut self, validity: Mask) {
420-
self.nulls.set_validity(validity);
421-
}
422-
423418
fn finish(&mut self) -> ArrayRef {
424419
self.finish_into_listview().into_array()
425420
}

0 commit comments

Comments
 (0)