Skip to content

Commit bd11897

Browse files
committed
fix: resolve lint failure and validate variant slots
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 50e53d1 commit bd11897

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

  • vortex-array/src/arrays

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::IntoArray;
2020
use crate::Precision;
2121
use crate::ToCanonical;
2222
use crate::arrays::ChunkedArray;
23-
use crate::arrays::Primitive;
2423
use crate::arrays::PrimitiveArray;
2524
use crate::arrays::chunked::compute::kernel::PARENT_KERNELS;
2625
use crate::arrays::chunked::compute::rules::PARENT_RULES;
@@ -226,9 +225,11 @@ impl VTable for Chunked {
226225

227226
#[cfg(debug_assertions)]
228227
{
229-
let chunk_offsets = chunk_offsets.as_opt::<Primitive>().unwrap_or_else(|| {
230-
vortex_panic!("Chunked array chunk_offsets slot must be primitive")
231-
});
228+
let chunk_offsets = chunk_offsets
229+
.as_opt::<crate::arrays::Primitive>()
230+
.unwrap_or_else(|| {
231+
vortex_panic!("Chunked array chunk_offsets slot must be primitive")
232+
});
232233
let chunk_offsets_buf = chunk_offsets.to_buffer::<u64>();
233234
debug_assert_eq!(
234235
chunk_offsets_buf.len(),

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::hash::Hasher;
99
use vortex_error::VortexExpect;
1010
use vortex_error::VortexResult;
1111
use vortex_error::vortex_ensure;
12+
use vortex_error::vortex_err;
1213
use vortex_error::vortex_panic;
1314

1415
use crate::ArrayEq;
@@ -142,7 +143,12 @@ impl VTable for Variant {
142143
NUM_SLOTS,
143144
slots.len()
144145
);
145-
array.slots = [slots.into_iter().next().vortex_expect("must exist")];
146+
let child = slots
147+
.into_iter()
148+
.next()
149+
.vortex_expect("VariantArray slot vector length was validated")
150+
.ok_or_else(|| vortex_err!("VariantArray child slot must be present"))?;
151+
array.slots = [Some(child)];
146152
Ok(())
147153
}
148154

@@ -151,3 +157,22 @@ impl VTable for Variant {
151157
Ok(ExecutionStep::done(array.clone().into_array()))
152158
}
153159
}
160+
161+
#[cfg(test)]
162+
mod tests {
163+
use super::*;
164+
use crate::arrays::PrimitiveArray;
165+
use crate::dtype::Nullability;
166+
167+
#[test]
168+
fn with_slots_rejects_missing_child() {
169+
let mut array = VariantArray::new(
170+
PrimitiveArray::from_iter([1u8, 2, 3]).into_array(),
171+
Nullability::NonNullable,
172+
);
173+
174+
let err = <Variant as VTable>::with_slots(&mut array, vec![None]).unwrap_err();
175+
176+
assert!(err.to_string().contains("child slot must be present"));
177+
}
178+
}

0 commit comments

Comments
 (0)