Skip to content

Commit 2a098ef

Browse files
committed
add test
Signed-off-by: Andrew Duffy <andrew@a10y.dev>
1 parent 6b5c2f8 commit 2a098ef

1 file changed

Lines changed: 39 additions & 3 deletions

File tree

  • vortex-array/src/arrays/patched/vtable

vortex-array/src/arrays/patched/vtable/mod.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,15 @@ impl VTable for Patched {
301301
let values = array.values.clone().execute::<PrimitiveArray>(ctx)?;
302302

303303
let patched_values = match_each_native_ptype!(values.ptype(), |V| {
304-
let mut output = Buffer::<V>::from_byte_buffer(buffer.unwrap_host()).into_mut();
305-
306304
let offset = array.offset;
307305
let len = array.len;
308306

307+
// Slice the buffer and validity from the offset.
308+
let buffer = buffer.slice_typed::<V>(offset..offset + len);
309+
let validity = validity.slice(offset..offset + len)?;
310+
311+
let mut output = Buffer::<V>::from_byte_buffer(buffer.unwrap_host()).into_mut();
312+
309313
apply_patches_primitive::<V>(
310314
&mut output,
311315
offset,
@@ -317,7 +321,7 @@ impl VTable for Patched {
317321
values.as_slice::<V>(),
318322
);
319323

320-
let output = output.freeze().slice(offset..offset + len);
324+
let output = output.freeze();
321325

322326
PrimitiveArray::from_byte_buffer(output.into_byte_buffer(), ptype, validity)
323327
});
@@ -421,6 +425,38 @@ mod tests {
421425
assert_eq!(executed, expected.freeze());
422426
}
423427

428+
#[test]
429+
fn test_execute_sliced() {
430+
let values = buffer![0u16; 1024].into_array();
431+
let patches = Patches::new(
432+
1024,
433+
0,
434+
buffer![1u32, 2, 3].into_array(),
435+
buffer![1u16; 3].into_array(),
436+
None,
437+
)
438+
.unwrap();
439+
440+
let session = VortexSession::empty();
441+
let mut ctx = ExecutionCtx::new(session);
442+
443+
let array = PatchedArray::from_array_and_patches(values, &patches, &mut ctx)
444+
.unwrap()
445+
.slice(3..1024)
446+
.unwrap();
447+
448+
let executed = array
449+
.execute::<Canonical>(&mut ctx)
450+
.unwrap()
451+
.into_primitive()
452+
.into_buffer::<u16>();
453+
454+
let mut expected = buffer_mut![0u16; 1021];
455+
expected[0] = 1;
456+
457+
assert_eq!(executed, expected.freeze());
458+
}
459+
424460
#[test]
425461
fn test_append_to_builder_non_nullable() {
426462
let values = PrimitiveArray::new(buffer![0u16; 1024], Validity::NonNullable).into_array();

0 commit comments

Comments
 (0)