diff --git a/tests/it/ffi.rs b/tests/it/ffi.rs index facc143988c..c7912d6cd81 100644 --- a/tests/it/ffi.rs +++ b/tests/it/ffi.rs @@ -1,13 +1,12 @@ use arrow2::array::*; +use arrow2::bitmap::Bitmap; use arrow2::datatypes::{DataType, Field, TimeUnit}; use arrow2::{error::Result, ffi}; use std::collections::BTreeMap; use std::sync::Arc; -fn test_round_trip(expected: impl Array + Clone + 'static) -> Result<()> { - let array: Arc = Arc::new(expected.clone()); +fn _test_round_trip(array: Arc, expected: Box) -> Result<()> { let field = Field::new("a", array.data_type().clone(), true); - let expected = Box::new(expected) as Box; let array_ptr = Box::new(ffi::Ffi_ArrowArray::empty()); let schema_ptr = Box::new(ffi::Ffi_ArrowSchema::empty()); @@ -32,6 +31,15 @@ fn test_round_trip(expected: impl Array + Clone + 'static) -> Result<()> { Ok(()) } +fn test_round_trip(expected: impl Array + Clone + 'static) -> Result<()> { + let array: Arc = Arc::new(expected.clone()); + let expected = Box::new(expected) as Box; + _test_round_trip(array.clone(), clone(expected.as_ref()))?; + + // sliced + _test_round_trip(array.slice(1, 2).into(), expected.slice(1, 2)) +} + fn test_round_trip_schema(field: Field) -> Result<()> { // create a `ArrowArray` from the data. let schema_ptr = Box::new(ffi::Ffi_ArrowSchema::empty()); @@ -138,6 +146,17 @@ fn list_list() -> Result<()> { test_round_trip(array) } +#[test] +fn struct_() -> Result<()> { + let data_type = DataType::Struct(vec![Field::new("a", DataType::Int32, true)]); + let values = vec![Arc::new(Int32Array::from([Some(1), None, Some(3)])) as Arc]; + let validity = Bitmap::from([true, false, true]); + + let array = StructArray::from_data(data_type, values, validity.into()); + + test_round_trip(array) +} + #[test] fn dict() -> Result<()> { let data = vec![Some("a"), Some("a"), None, Some("b")];