Skip to content

Commit 0b928a6

Browse files
committed
Add unit test
1 parent ec5bc9a commit 0b928a6

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

arrow-array/src/ffi.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ mod tests_to_then_from_ffi {
12241224
mod tests_from_ffi {
12251225
use std::sync::Arc;
12261226

1227-
use arrow_buffer::{bit_util, buffer::Buffer};
1227+
use arrow_buffer::{bit_util, buffer::Buffer, MutableBuffer, OffsetBuffer};
12281228
use arrow_data::ArrayData;
12291229
use arrow_schema::{DataType, Field};
12301230

@@ -1236,7 +1236,7 @@ mod tests_from_ffi {
12361236
ffi::{from_ffi, FFI_ArrowArray, FFI_ArrowSchema},
12371237
};
12381238

1239-
use super::Result;
1239+
use super::{ImportedArrowArray, Result};
12401240

12411241
fn test_round_trip(expected: &ArrayData) -> Result<()> {
12421242
// here we export the array
@@ -1428,4 +1428,34 @@ mod tests_from_ffi {
14281428
let data = array.into_data();
14291429
test_round_trip(&data)
14301430
}
1431+
1432+
#[test]
1433+
fn test_empty_string_with_non_zero_offset() -> Result<()> {
1434+
// Simulate an empty string array with a non-zero offset from a producer
1435+
let data: Buffer = MutableBuffer::new(0).into();
1436+
let offsets = OffsetBuffer::new(vec![123].into());
1437+
let string_array =
1438+
unsafe { StringArray::new_unchecked(offsets.clone(), data.clone(), None) };
1439+
1440+
let data = string_array.into_data();
1441+
1442+
let array = FFI_ArrowArray::new(&data);
1443+
let schema = FFI_ArrowSchema::try_from(data.data_type())?;
1444+
1445+
let dt = DataType::try_from(&schema)?;
1446+
let array = Arc::new(array);
1447+
let imported_array = ImportedArrowArray {
1448+
array: &array,
1449+
data_type: dt,
1450+
owner: &array,
1451+
};
1452+
1453+
let offset_buf_len = imported_array.buffer_len(1, &imported_array.data_type)?;
1454+
let data_buf_len = imported_array.buffer_len(2, &imported_array.data_type)?;
1455+
1456+
assert_eq!(offset_buf_len, 4);
1457+
assert_eq!(data_buf_len, 0);
1458+
1459+
Ok(())
1460+
}
14311461
}

0 commit comments

Comments
 (0)