This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0956c5
commit ff810eb
Showing
6 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::{array::FromFfi, error::Result, ffi}; | ||
|
||
use super::super::{ffi::ToFfi, Array}; | ||
use super::UnionArray; | ||
|
||
unsafe impl ToFfi for UnionArray { | ||
fn buffers(&self) -> Vec<Option<std::ptr::NonNull<u8>>> { | ||
if let Some(offsets) = &self.offsets { | ||
vec![ | ||
None, | ||
std::ptr::NonNull::new(self.types.as_ptr() as *mut u8), | ||
std::ptr::NonNull::new(offsets.as_ptr() as *mut u8), | ||
] | ||
} else { | ||
vec![None, std::ptr::NonNull::new(self.types.as_ptr() as *mut u8)] | ||
} | ||
} | ||
|
||
fn offset(&self) -> usize { | ||
self.offset | ||
} | ||
|
||
fn children(&self) -> Vec<Arc<dyn Array>> { | ||
self.fields.clone() | ||
} | ||
} | ||
|
||
unsafe impl<A: ffi::ArrowArrayRef> FromFfi<A> for UnionArray { | ||
fn try_from_ffi(array: A) -> Result<Self> { | ||
let field = array.field()?; | ||
let data_type = field.data_type().clone(); | ||
let fields = Self::get_fields(field.data_type()); | ||
|
||
// 0 is null bitmap (which was deprecated for the union type) | ||
let mut types = unsafe { array.buffer::<i8>(0) }?; | ||
let offsets = if Self::is_sparse(&data_type) { | ||
None | ||
} else { | ||
Some(unsafe { array.buffer::<i32>(1) }?) | ||
}; | ||
|
||
let length = array.array().len(); | ||
let offset = array.array().offset(); | ||
let fields = (0..fields.len()) | ||
.map(|index| { | ||
let child = array.child(index)?; | ||
Ok(ffi::try_from(child)?.into()) | ||
}) | ||
.collect::<Result<Vec<Arc<dyn Array>>>>()?; | ||
|
||
if offset > 0 { | ||
types = types.slice(offset, length); | ||
}; | ||
|
||
Ok(Self::from_data(data_type, types, fields, offsets)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters