Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Added ArrayStream struct
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Feb 21, 2022
1 parent 679ce0c commit 5a251aa
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 42 deletions.
25 changes: 2 additions & 23 deletions src/ffi/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::{
types::NativeType,
};

use super::ArrowArray;

/// Reads a valid `ffi` interface into a `Box<dyn Array>`
/// # Errors
/// If and only if:
Expand Down Expand Up @@ -45,29 +47,6 @@ pub unsafe fn try_from<A: ArrowArrayRef>(array: A) -> Result<Box<dyn Array>> {
})
}

/// ABI-compatible struct for ArrowArray from C Data Interface
/// See <https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions>
/// This was created by bindgen
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ArrowArray {
pub(crate) length: i64,
pub(crate) null_count: i64,
pub(crate) offset: i64,
pub(crate) n_buffers: i64,
pub(crate) n_children: i64,
pub(crate) buffers: *mut *const ::std::os::raw::c_void,
children: *mut *mut ArrowArray,
dictionary: *mut ArrowArray,
release: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ArrowArray)>,
// When exported, this MUST contain everything that is owned by this array.
// for example, any buffer pointed to in `buffers` must be here, as well as the `buffers` pointer
// itself.
// In other words, everything in [ArrowArray] must be owned by `private_data` and can assume
// that they do not outlive `private_data`.
private_data: *mut ::std::os::raw::c_void,
}

// Sound because the arrow specification does not allow multiple implementations
// to change this struct
// This is intrinsically impossible to prove because the implementations agree
Expand Down
56 changes: 56 additions & 0 deletions src/ffi/generated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* automatically generated by rust-bindgen 0.59.2 */

/// ABI-compatible struct for `ArrowSchema` from C Data Interface
/// See <https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions>
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ArrowSchema {
pub(super) format: *const ::std::os::raw::c_char,
pub(super) name: *const ::std::os::raw::c_char,
pub(super) metadata: *const ::std::os::raw::c_char,
pub(super) flags: i64,
pub(super) n_children: i64,
pub(super) children: *mut *mut ArrowSchema,
pub(super) dictionary: *mut ArrowSchema,
pub(super) release: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ArrowSchema)>,
pub(super) private_data: *mut ::std::os::raw::c_void,
}

/// ABI-compatible struct for `ArrowArray` from C Data Interface
/// See <https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions>
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ArrowArray {
pub(super) length: i64,
pub(super) null_count: i64,
pub(super) offset: i64,
pub(super) n_buffers: i64,
pub(super) n_children: i64,
pub(super) buffers: *mut *const ::std::os::raw::c_void,
pub(super) children: *mut *mut ArrowArray,
pub(super) dictionary: *mut ArrowArray,
pub(super) release: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ArrowArray)>,
pub(super) private_data: *mut ::std::os::raw::c_void,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ArrowArrayStream {
get_schema: ::std::option::Option<
unsafe extern "C" fn(
arg1: *mut ArrowArrayStream,
out: *mut ArrowSchema,
) -> ::std::os::raw::c_int,
>,
get_next: ::std::option::Option<
unsafe extern "C" fn(
arg1: *mut ArrowArrayStream,
out: *mut ArrowArray,
) -> ::std::os::raw::c_int,
>,
get_last_error: ::std::option::Option<
unsafe extern "C" fn(arg1: *mut ArrowArrayStream) -> *const ::std::os::raw::c_char,
>,
release: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ArrowArrayStream)>,
private_data: *mut ::std::os::raw::c_void,
}
4 changes: 2 additions & 2 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! Arrow's [C Data Interface](https://arrow.apache.org/docs/format/CDataInterface.html)
mod array;
mod bridge;
mod generated;
mod schema;

pub(crate) use array::try_from;
Expand All @@ -15,8 +16,7 @@ use crate::error::Result;

use self::schema::to_field;

pub use array::ArrowArray;
pub use schema::ArrowSchema;
pub use generated::{ArrowArray, ArrowSchema};

/// Exports an [`Arc<dyn Array>`] to the C data interface.
/// # Safety
Expand Down
19 changes: 2 additions & 17 deletions src/ffi/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::{
error::{ArrowError, Result},
};

use super::ArrowSchema;

#[allow(dead_code)]
struct SchemaPrivateData {
name: CString,
Expand All @@ -16,23 +18,6 @@ struct SchemaPrivateData {
dictionary: Option<*mut ArrowSchema>,
}

/// ABI-compatible struct for `ArrowSchema` from C Data Interface
/// See <https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions>
// This was created by bindgen
#[repr(C)]
#[derive(Debug)]
pub struct ArrowSchema {
format: *const ::std::os::raw::c_char,
name: *const ::std::os::raw::c_char,
metadata: *const ::std::os::raw::c_char,
flags: i64,
n_children: i64,
children: *mut *mut ArrowSchema,
dictionary: *mut ArrowSchema,
release: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ArrowSchema)>,
private_data: *mut ::std::os::raw::c_void,
}

// callback used to drop [ArrowSchema] when it is exported.
unsafe extern "C" fn c_release_schema(schema: *mut ArrowSchema) {
if schema.is_null() {
Expand Down

0 comments on commit 5a251aa

Please sign in to comment.