Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FFI for Arrow C Stream Interface #1384

Merged
merged 24 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arrow/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub enum ArrowError {
ParquetError(String),
/// Error during import or export to/from the C Data Interface
CDataInterface(String),
/// Error during import or export to/from the C Stream Interface
CStreamInterface(String),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the Stream interface is built on the CDataInterface, what do you think about just reusing the same CDataInterface error variant instead of adding a new one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

DictionaryKeyOverflowError,
}

Expand Down Expand Up @@ -122,6 +124,9 @@ impl Display for ArrowError {
ArrowError::CDataInterface(desc) => {
write!(f, "C Data interface error: {}", desc)
}
ArrowError::CStreamInterface(desc) => {
write!(f, "C Stream interface error: {}", desc)
}
ArrowError::DictionaryKeyOverflowError => {
write!(f, "Dictionary key bigger than the key type")
}
Expand Down
32 changes: 16 additions & 16 deletions arrow/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ bitflags! {
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FFI_ArrowSchema {
format: *const c_char,
name: *const c_char,
metadata: *const c_char,
flags: i64,
n_children: i64,
children: *mut *mut FFI_ArrowSchema,
dictionary: *mut FFI_ArrowSchema,
release: Option<unsafe extern "C" fn(arg1: *mut FFI_ArrowSchema)>,
private_data: *mut c_void,
pub(crate) format: *const c_char,
pub(crate) name: *const c_char,
pub(crate) metadata: *const c_char,
pub(crate) flags: i64,
pub(crate) n_children: i64,
pub(crate) children: *mut *mut FFI_ArrowSchema,
pub(crate) dictionary: *mut FFI_ArrowSchema,
pub(crate) release: Option<unsafe extern "C" fn(arg1: *mut FFI_ArrowSchema)>,
pub(crate) private_data: *mut c_void,
}

struct SchemaPrivateData {
Expand Down Expand Up @@ -324,15 +324,15 @@ pub struct FFI_ArrowArray {
pub(crate) n_buffers: i64,
pub(crate) n_children: i64,
pub(crate) buffers: *mut *const c_void,
children: *mut *mut FFI_ArrowArray,
dictionary: *mut FFI_ArrowArray,
release: Option<unsafe extern "C" fn(arg1: *mut FFI_ArrowArray)>,
pub(crate) children: *mut *mut FFI_ArrowArray,
pub(crate) dictionary: *mut FFI_ArrowArray,
pub(crate) release: Option<unsafe extern "C" fn(arg1: *mut FFI_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 [FFI_ArrowArray] must be owned by
// `private_data` and can assume that they do not outlive `private_data`.
private_data: *mut c_void,
pub(crate) private_data: *mut c_void,
}

impl Drop for FFI_ArrowArray {
Expand Down Expand Up @@ -372,7 +372,7 @@ impl FFI_ArrowArray {
/// # Safety
/// This method releases `buffers`. Consumers of this struct *must* call `release` before
/// releasing this struct, or contents in `buffers` leak.
fn new(data: &ArrayData) -> Self {
pub fn new(data: &ArrayData) -> Self {
// * insert the null buffer at the start
// * make all others `Option<Buffer>`.
let buffers = iter::once(data.null_buffer().cloned())
Expand Down Expand Up @@ -646,8 +646,8 @@ pub trait ArrowArrayRef {
/// Furthermore, this struct assumes that the incoming data agrees with the C data interface.
#[derive(Debug)]
pub struct ArrowArray {
array: Arc<FFI_ArrowArray>,
schema: Arc<FFI_ArrowSchema>,
pub(crate) array: Arc<FFI_ArrowArray>,
pub(crate) schema: Arc<FFI_ArrowSchema>,
}

#[derive(Debug)]
Expand Down
Loading