diff --git a/libraries/arrow-convert/src/from_impls.rs b/libraries/arrow-convert/src/from_impls.rs index 5b0b687d1..8d918a3aa 100644 --- a/libraries/arrow-convert/src/from_impls.rs +++ b/libraries/arrow-convert/src/from_impls.rs @@ -1,5 +1,5 @@ use arrow::{ - array::{Array, AsArray, PrimitiveArray, StringArray}, + array::{make_array, Array, AsArray, PrimitiveArray, StringArray}, datatypes::ArrowPrimitiveType, }; use eyre::ContextCompat; @@ -136,6 +136,13 @@ impl<'a> TryFrom<&'a ArrowData> for &'a [u8] { } } +impl<'a> TryFrom<&'a ArrowData> for Vec { + type Error = eyre::Report; + fn try_from(value: &'a ArrowData) -> Result { + value.try_into().map(|slice: &'a [u8]| slice.to_vec()) + } +} + fn extract_single_primitive(array: &PrimitiveArray) -> Result where T: ArrowPrimitiveType, @@ -151,3 +158,19 @@ where } Ok(array.value(0)) } + +#[cfg(test)] +mod tests { + use arrow::array::{make_array, PrimitiveArray}; + + use crate::ArrowData; + + #[test] + fn test_u8() { + let array = + make_array(PrimitiveArray::::from(vec![42]).into()); + let data: ArrowData = array.into(); + let value: u8 = (&data).try_into().unwrap(); + assert_eq!(value, 42); + } +} diff --git a/libraries/message/src/lib.rs b/libraries/message/src/lib.rs index 889949423..035cbd3b0 100644 --- a/libraries/message/src/lib.rs +++ b/libraries/message/src/lib.rs @@ -82,7 +82,7 @@ impl ArrowTypeInfo { let offset = usize::try_from(unsafe { ptr.offset_from(region_start) }) .context("offset_from is negative")?; - Ok(BufferOffset { + Result::<_, eyre::Report>::Ok(BufferOffset { offset, len: b.len(), })