MCPcopy Create free account
hub / github.com/apache/arrow-rs / _test_round_trip_export

Function _test_round_trip_export

arrow-array/src/ffi_stream.rs:428–471  ·  view source on GitHub ↗
(batch: RecordBatch, schema: Arc<Schema>)

Source from the content-addressed store, hash-verified

426 }
427
428 fn _test_round_trip_export(batch: RecordBatch, schema: Arc<Schema>) -> Result<()> {
429 let iter = Box::new(vec![batch.clone(), batch.clone()].into_iter().map(Ok)) as _;
430
431 let reader = TestRecordBatchReader::new(schema.clone(), iter);
432
433 // Export a `RecordBatchReader` through `FFI_ArrowArrayStream`
434 let mut ffi_stream = FFI_ArrowArrayStream::new(reader);
435
436 // Get schema from `FFI_ArrowArrayStream`
437 let mut ffi_schema = FFI_ArrowSchema::empty();
438 let ret_code = unsafe { get_schema(&mut ffi_stream, &mut ffi_schema) };
439 assert_eq!(ret_code, 0);
440
441 let exported_schema = Schema::try_from(&ffi_schema).unwrap();
442 assert_eq!(&exported_schema, schema.as_ref());
443
444 // Get array from `FFI_ArrowArrayStream`
445 let mut produced_batches = vec![];
446 loop {
447 let mut ffi_array = FFI_ArrowArray::empty();
448 let ret_code = unsafe { get_next(&mut ffi_stream, &mut ffi_array) };
449 assert_eq!(ret_code, 0);
450
451 // The end of stream has been reached
452 if ffi_array.is_released() {
453 break;
454 }
455
456 let array = unsafe { from_ffi(ffi_array, &ffi_schema) }.unwrap();
457 let len = array.len();
458
459 let record_batch = RecordBatch::try_new_with_options(
460 SchemaRef::from(exported_schema.clone()),
461 StructArray::from(array).into_parts().1,
462 &RecordBatchOptions::new().with_row_count(Some(len)),
463 )
464 .unwrap();
465 produced_batches.push(record_batch);
466 }
467
468 assert_eq!(produced_batches, vec![batch.clone(), batch]);
469
470 Ok(())
471 }
472
473 fn _test_round_trip_import(batch: RecordBatch, schema: Arc<Schema>) -> Result<()> {
474 let iter = Box::new(vec![batch.clone(), batch.clone()].into_iter().map(Ok)) as _;

Callers 2

test_stream_round_tripFunction · 0.85

Calls 10

get_schemaFunction · 0.85
get_nextFunction · 0.85
from_ffiFunction · 0.85
is_releasedMethod · 0.80
with_row_countMethod · 0.80
into_iterMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45
into_partsMethod · 0.45
pushMethod · 0.45

Tested by 2

test_stream_round_tripFunction · 0.68