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 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for FFI of dictionary-encoded arrays (#267)
- Loading branch information
1 parent
01cba03
commit d988539
Showing
14 changed files
with
485 additions
and
342 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
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,39 @@ | ||
use crate::{ | ||
array::{FromFfi, PrimitiveArray, ToFfi}, | ||
error::Result, | ||
ffi, | ||
}; | ||
|
||
use super::{DictionaryArray, DictionaryKey}; | ||
|
||
unsafe impl<K: DictionaryKey> ToFfi for DictionaryArray<K> { | ||
fn buffers(&self) -> Vec<Option<std::ptr::NonNull<u8>>> { | ||
self.keys.buffers() | ||
} | ||
|
||
#[inline] | ||
fn offset(&self) -> usize { | ||
self.offset | ||
} | ||
} | ||
|
||
unsafe impl<K: DictionaryKey, A: ffi::ArrowArrayRef> FromFfi<A> for DictionaryArray<K> { | ||
fn try_from_ffi(array: A) -> Result<Self> { | ||
// keys: similar to PrimitiveArray, but the datatype is the inner one | ||
let length = array.array().len(); | ||
let offset = array.array().offset(); | ||
let mut validity = unsafe { array.validity() }?; | ||
let mut values = unsafe { array.buffer::<K>(0) }?; | ||
|
||
if offset > 0 { | ||
values = values.slice(offset, length); | ||
validity = validity.map(|x| x.slice(offset, length)) | ||
} | ||
let keys = PrimitiveArray::<K>::from_data(K::DATA_TYPE, values, validity); | ||
// values | ||
let values = array.dictionary()?.unwrap(); | ||
let values = ffi::try_from(values)?.into(); | ||
|
||
Ok(DictionaryArray::<K>::from_data(keys, values)) | ||
} | ||
} |
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
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
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
Oops, something went wrong.