Expand description
Contains declarations to bind to the C Data Interface.
Generally, this module is divided in 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_ArrowSchema and FFI_ArrowArray.
The second interface maps native Rust types to the Rust-specific implementation of Arrow such as format
to Datatype
,
Buffer
, etc. This is handled by from_ffi
and to_ffi
.
Export to FFI
// create an array natively
let array = Int32Array::from(vec![Some(1), None, Some(3)]);
let data = array.into_data();
// Export it
let (out_array, out_schema) = to_ffi(&data)?;
// import it
let data = unsafe { from_ffi(out_array, &out_schema) }?;
let array = Int32Array::from(data);
// verify
assert_eq!(array, Int32Array::from(vec![Some(1), None, Some(3)]));
Import from FFI
/// A foreign data container that can export to C Data interface
struct ForeignArray {};
impl ForeignArray {
/// Export from foreign array representation to C Data interface
/// e.g. <https://github.com/apache/arrow/blob/fc1f9ebbc4c3ae77d5cfc2f9322f4373d3d19b8a/python/pyarrow/array.pxi#L1552>
fn export_to_c(&self, array: *mut FFI_ArrowArray, schema: *mut FFI_ArrowSchema) {
// ...
}
}
/// Import an [`ArrayRef`] from a [`ForeignArray`]
fn import_array(foreign: &ForeignArray) -> Result<ArrayRef, ArrowError> {
let mut schema = FFI_ArrowSchema::empty();
let mut array = FFI_ArrowArray::empty();
foreign.export_to_c(addr_of_mut!(array), addr_of_mut!(schema));
Ok(make_array(unsafe { from_ffi(array, &schema) }?))
}
Structsยง
- FFI_
Arrow Array - ABI-compatible struct for ArrowArray from C Data Interface See https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions
- FFI_
Arrow Schema - ABI-compatible struct for
ArrowSchema
from C Data Interface See https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions - Imported
Arrow ๐Array
Functionsยง
- bit_
width ๐ - create_
buffer ๐ โ - returns a new buffer corresponding to the index
i
of the FFI array. It may not exist (null pointer).bits
is the number of bits that the native type of this buffer has. The size of the buffer will beceil(self.length * bits, 8)
. - export_
array_ โinto_ raw Deprecated - Exports an array to raw pointers of the C Data Interface provided by the consumer.
- from_
ffi โ - Import ArrayData from the C Data Interface
- from_
ffi_ โand_ data_ type - Import ArrayData from the C Data Interface
- to_ffi
- Export to the C Data Interface
Type Aliasesยง
- Result ๐