Skip to content

Commit bd6e3c4

Browse files
committed
fix: add append_values method on BinaryViewVectorMut
Also add validation tests that use the methods and check that constructors error when they're supposed to. Signed-off-by: Andrew Duffy <[email protected]>
1 parent be9e105 commit bd6e3c4

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

vortex-vector/src/binaryview/vector.rs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::sync::Arc;
77

88
use vortex_buffer::{Buffer, ByteBuffer};
9-
use vortex_error::{VortexExpect, VortexResult};
9+
use vortex_error::{VortexExpect, VortexResult, vortex_ensure};
1010
use vortex_mask::Mask;
1111

1212
use crate::VectorOps;
@@ -81,6 +81,13 @@ impl<T: BinaryViewType> BinaryViewVector<T> {
8181
buffers: Arc<Box<[ByteBuffer]>>,
8282
validity: Mask,
8383
) -> VortexResult<Self> {
84+
vortex_ensure!(
85+
views.len() == validity.len(),
86+
"views buffer length {} != validity length {}",
87+
views.len(),
88+
validity.len()
89+
);
90+
8491
validate_views(
8592
&views,
8693
&*buffers,
@@ -203,9 +210,74 @@ impl<T: BinaryViewType> VectorOps for BinaryViewVector<T> {
203210

204211
#[cfg(test)]
205212
mod tests {
206-
use crate::binaryview::StringVectorMut;
213+
use std::sync::Arc;
214+
215+
use vortex_buffer::{ByteBuffer, buffer};
216+
use vortex_mask::Mask;
217+
218+
use crate::binaryview::view::BinaryView;
219+
use crate::binaryview::{StringVector, StringVectorMut};
207220
use crate::{VectorMutOps, VectorOps};
208221

222+
#[test]
223+
#[should_panic(expected = "views buffer length 1 != validity length 100")]
224+
fn test_try_new_mismatch_validity_len() {
225+
StringVector::try_new(
226+
buffer![BinaryView::new_inlined(b"inlined")],
227+
Arc::new(Box::new([])),
228+
Mask::new_true(100),
229+
)
230+
.unwrap();
231+
}
232+
233+
#[test]
234+
#[should_panic(
235+
expected = "view at index 0 references invalid buffer: 100 out of bounds for BinaryViewVector with 0 buffers"
236+
)]
237+
fn test_try_new_invalid_buffer_offset() {
238+
StringVector::try_new(
239+
buffer![BinaryView::make_view(b"bad buffer ptr", 100, 0)],
240+
Arc::new(Box::new([])),
241+
Mask::new_true(1),
242+
)
243+
.unwrap();
244+
}
245+
246+
#[test]
247+
#[should_panic(expected = "start offset 4294967295 out of bounds for buffer 0 with size 19")]
248+
fn test_try_new_invalid_length() {
249+
StringVector::try_new(
250+
buffer![BinaryView::make_view(b"bad buffer ptr", 0, u32::MAX)],
251+
Arc::new(Box::new([ByteBuffer::copy_from(b"a very short buffer")])),
252+
Mask::new_true(1),
253+
)
254+
.unwrap();
255+
}
256+
257+
#[test]
258+
#[should_panic(expected = "view at index 0: inlined bytes failed utf-8 validation")]
259+
fn test_try_new_invalid_utf8_inlined() {
260+
StringVector::try_new(
261+
buffer![BinaryView::new_inlined(b"\x80")],
262+
Arc::new(Box::new([])),
263+
Mask::new_true(1),
264+
)
265+
.unwrap();
266+
}
267+
268+
#[test]
269+
#[should_panic(expected = "view at index 0: outlined bytes failed utf-8 validation")]
270+
fn test_try_new_invalid_utf8_outlined() {
271+
// 0xFF is never valid in UTF-8
272+
let sequence = b"\xff".repeat(13);
273+
StringVector::try_new(
274+
buffer![BinaryView::make_view(&sequence, 0, 0)],
275+
Arc::new(Box::new([ByteBuffer::copy_from(sequence)])),
276+
Mask::new_true(1),
277+
)
278+
.unwrap();
279+
}
280+
209281
#[test]
210282
fn test_try_into_mut() {
211283
let mut shared_vec = StringVectorMut::with_capacity(5);

vortex-vector/src/binaryview/view.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ where
304304
let end_offset = start_offset.saturating_add(view.size as usize);
305305

306306
let buf = buffers.get(buf_index).ok_or_else(||
307-
vortex_err!("view at index {idx} references invalid buffer: {buf_index} out of bounds for VarBinViewArray with {} buffers",
307+
vortex_err!("view at index {idx} references invalid buffer: {buf_index} out of bounds for BinaryViewVector with {} buffers",
308308
buffers.len()))?;
309309

310310
vortex_ensure!(
@@ -329,7 +329,7 @@ where
329329
// Validate the full string
330330
vortex_ensure!(
331331
validator(bytes),
332-
"view at index {idx}: outlined bytes fails utf-8 validation"
332+
"view at index {idx}: outlined bytes failed utf-8 validation"
333333
);
334334
}
335335
}

0 commit comments

Comments
 (0)