Skip to main content

Module ffi_stream

Module ffi_stream 

Source
Expand description

Contains declarations to bind to the C Stream Interface.

This module has two main interfaces: One interface maps C ABI to native Rust types, i.e. convert c-pointers, c_char, to native rust. This is handled by FFI_ArrowArrayStream.

The second interface is used to import FFI_ArrowArrayStream as a Rust reader. A stream whose top-level type is Struct can be read as RecordBatch by RecordBatchStreamReader; a stream of any type can be read as ArrayRef by ArrayStreamReader.

β“˜
// create an record batch reader natively
let file = File::open("arrow_file").unwrap();
let reader = Box::new(FileReader::try_new(file).unwrap());

// export it
let mut stream = FFI_ArrowArrayStream::empty();
unsafe { export_reader_into_raw(reader, &mut stream) };

// consumed and used by something else...

// import it
let stream_reader = unsafe { RecordBatchStreamReader::from_raw(&mut stream).unwrap() };
let imported_schema = stream_reader.schema();

let mut produced_batches = vec![];
for batch in stream_reader {
     produced_batches.push(batch.unwrap());
}
Ok(())
}

Re-exportsΒ§

use arrow_schema::DataType; πŸ”’
use std::ffi::CStr; πŸ”’
use std::ptr::addr_of; πŸ”’
use std::ffi::CString; πŸ”’
use std::os::raw::c_char; πŸ”’
use std::os::raw::c_int; πŸ”’
use std::os::raw::c_void; πŸ”’
use std::sync::Arc; πŸ”’
use arrow_data::ffi::FFI_ArrowArray; πŸ”’
use arrow_schema::ArrowError; πŸ”’
use arrow_schema::Field; πŸ”’
use arrow_schema::FieldRef; πŸ”’
use arrow_schema::Schema; πŸ”’
use arrow_schema::SchemaRef; πŸ”’
use arrow_schema::ffi::FFI_ArrowSchema; πŸ”’
use crate::RecordBatchOptions; πŸ”’
use crate::array::Array; πŸ”’
use crate::array::StructArray; πŸ”’
use crate::array::ArrayRef; πŸ”’
use crate::array::make_array; πŸ”’
use crate::array_reader::ArrayReader; πŸ”’
use crate::ffi::from_ffi_and_data_type; πŸ”’
use crate::record_batch::RecordBatch; πŸ”’
use crate::record_batch::RecordBatchReader; πŸ”’
use libc::EINVAL; πŸ”’
use libc::EIO; πŸ”’
use libc::ENOMEM; πŸ”’
use libc::ENOSYS; πŸ”’

StructsΒ§

ArrayStreamReader
An ArrayReader which imports arrays from an FFI_ArrowArrayStream.
ExportedArrayStream πŸ”’
FFI_ArrowArrayStream
ABI-compatible struct for ArrayStream from C Stream Interface See https://arrow.apache.org/docs/format/CStreamInterface.html#structure-definitions This was created by bindgen
RecordBatchStreamReader
A RecordBatchReader which imports Arrays from FFI_ArrowArrayStream.
StreamPrivateData πŸ”’

FunctionsΒ§

get_error_code πŸ”’
get_last_error πŸ”’ ⚠
get_next πŸ”’ ⚠
get_schema πŸ”’ ⚠
get_stream_field πŸ”’
Gets the field from a raw pointer of FFI_ArrowArrayStream. This is used when constructing ArrayStreamReader to cache the field.
get_stream_schema πŸ”’
Gets schema from a raw pointer of FFI_ArrowArrayStream. This is used when constructing RecordBatchStreamReader to cache schema.
producer_error πŸ”’ ⚠
Returns the producer’s message for the last failed call on a FFI_ArrowArrayStream.
release_stream πŸ”’ ⚠

Type AliasesΒ§

ArrowArrayStreamReaderDeprecated
Renamed to RecordBatchStreamReader, to distinguish it from ArrayStreamReader.
Result πŸ”’