-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-12052: [Rust] Add Child Data to Arrow's C FFI implementation. … #9778
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
Changes from all commits
80f6406
8376922
be102d2
44efefb
24e88b5
dd50114
7101de3
4fe20df
ef14a99
d7c599c
104dc1f
acd93b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,12 +25,23 @@ use crate::{ | |
| }; | ||
|
|
||
| use super::ArrayData; | ||
| use crate::datatypes::DataType; | ||
| use crate::ffi::ArrowArray; | ||
|
|
||
| impl TryFrom<ffi::ArrowArray> for ArrayData { | ||
| type Error = ArrowError; | ||
|
|
||
| fn try_from(value: ffi::ArrowArray) -> Result<Self> { | ||
| let data_type = value.data_type()?; | ||
| let child_data = value.children()?; | ||
|
|
||
| let child_type = if !child_data.is_empty() { | ||
| Some(child_data[0].data_type().clone()) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let data_type = value.data_type(child_type)?; | ||
|
|
||
| let len = value.len(); | ||
| let offset = value.offset(); | ||
| let null_count = value.null_count(); | ||
|
|
@@ -44,9 +55,7 @@ impl TryFrom<ffi::ArrowArray> for ArrayData { | |
| null_bit_buffer, | ||
| offset, | ||
| buffers, | ||
| // this is empty because ffi still does not support it. | ||
| // this is ok because FFI only supports datatypes without childs | ||
| vec![], | ||
| child_data, | ||
| )) | ||
| } | ||
| } | ||
|
|
@@ -55,11 +64,45 @@ impl TryFrom<ArrayData> for ffi::ArrowArray { | |
| type Error = ArrowError; | ||
|
|
||
| fn try_from(value: ArrayData) -> Result<Self> { | ||
| // If parent is nullable, then children also must be nullable | ||
| // so we pass this nullable to the creation of hte child data | ||
| let nullable = match value.data_type() { | ||
| DataType::List(field) => field.is_nullable(), | ||
| DataType::LargeList(field) => field.is_nullable(), | ||
| _ => false, | ||
| }; | ||
|
|
||
| let len = value.len(); | ||
| let offset = value.offset() as usize; | ||
| let null_count = value.null_count(); | ||
| let buffers = value.buffers().to_vec(); | ||
| let null_buffer = value.null_buffer().cloned(); | ||
| let child_data = value | ||
| .child_data() | ||
| .iter() | ||
| .map(|arr| { | ||
| let len = arr.len(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand: why isn't
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because I otherwise cannot pass
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, you'll need to handle recursive types more generally anyway. Think
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that would not work like this. I will fix that. |
||
| let offset = arr.offset() as usize; | ||
| let null_count = arr.null_count(); | ||
| let buffers = arr.buffers().to_vec(); | ||
| let null_buffer = arr.null_buffer().cloned(); | ||
|
|
||
| // Note: the nullable comes from the parent data. | ||
| unsafe { | ||
| ArrowArray::try_new( | ||
| arr.data_type(), | ||
| len, | ||
| null_count, | ||
| null_buffer, | ||
| offset, | ||
| buffers, | ||
| vec![], | ||
| nullable, | ||
| ) | ||
| .expect("infallible") | ||
| } | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| unsafe { | ||
| ffi::ArrowArray::try_new( | ||
|
|
@@ -69,9 +112,8 @@ impl TryFrom<ArrayData> for ffi::ArrowArray { | |
| null_buffer, | ||
| offset, | ||
| buffers, | ||
| // this is empty because ffi still does not support it. | ||
| // this is ok because FFI only supports datatypes without childs | ||
| vec![], | ||
| child_data, | ||
| nullable, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be interesting to add
del aabove this, to make sure thatbkeeps the data alive.