Skip to content

Commit 5ae6790

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 dacbb25 commit 5ae6790

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,7 +210,72 @@ impl<T: BinaryViewType> VectorOps for BinaryViewVector<T> {
203210

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

208280
#[test]
209281
fn test_try_into_mut() {

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)