@@ -1224,7 +1224,7 @@ mod tests_to_then_from_ffi {
1224
1224
mod tests_from_ffi {
1225
1225
use std:: sync:: Arc ;
1226
1226
1227
- use arrow_buffer:: { bit_util, buffer:: Buffer } ;
1227
+ use arrow_buffer:: { bit_util, buffer:: Buffer , MutableBuffer , OffsetBuffer } ;
1228
1228
use arrow_data:: ArrayData ;
1229
1229
use arrow_schema:: { DataType , Field } ;
1230
1230
@@ -1236,7 +1236,7 @@ mod tests_from_ffi {
1236
1236
ffi:: { from_ffi, FFI_ArrowArray , FFI_ArrowSchema } ,
1237
1237
} ;
1238
1238
1239
- use super :: Result ;
1239
+ use super :: { ImportedArrowArray , Result } ;
1240
1240
1241
1241
fn test_round_trip ( expected : & ArrayData ) -> Result < ( ) > {
1242
1242
// here we export the array
@@ -1428,4 +1428,34 @@ mod tests_from_ffi {
1428
1428
let data = array. into_data ( ) ;
1429
1429
test_round_trip ( & data)
1430
1430
}
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
+ }
1431
1461
}
0 commit comments