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
8237800
commit 959d549
Showing
38 changed files
with
886 additions
and
57 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
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,5 @@ | ||
use crate::array::{Array, UnionArray}; | ||
|
||
pub(super) fn equal(lhs: &UnionArray, rhs: &UnionArray) -> bool { | ||
lhs.data_type() == rhs.data_type() && lhs.len() == rhs.len() && lhs.iter().eq(rhs.iter()) | ||
} |
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,58 @@ | ||
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()); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use super::{Array, UnionArray}; | ||
use crate::{scalar::Scalar, trusted_len::TrustedLen}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct UnionIter<'a> { | ||
array: &'a UnionArray, | ||
current: usize, | ||
} | ||
|
||
impl<'a> UnionIter<'a> { | ||
pub fn new(array: &'a UnionArray) -> Self { | ||
Self { array, current: 0 } | ||
} | ||
} | ||
|
||
impl<'a> Iterator for UnionIter<'a> { | ||
type Item = Box<dyn Scalar>; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
if self.current == self.array.len() { | ||
None | ||
} else { | ||
let old = self.current; | ||
self.current += 1; | ||
Some(self.array.value(old)) | ||
} | ||
} | ||
|
||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
let len = self.array.len() - self.current; | ||
(len, Some(len)) | ||
} | ||
} | ||
|
||
impl<'a> IntoIterator for &'a UnionArray { | ||
type Item = Box<dyn Scalar>; | ||
type IntoIter = UnionIter<'a>; | ||
|
||
#[inline] | ||
fn into_iter(self) -> Self::IntoIter { | ||
self.iter() | ||
} | ||
} | ||
|
||
impl<'a> UnionArray { | ||
/// constructs a new iterator | ||
#[inline] | ||
pub fn iter(&'a self) -> UnionIter<'a> { | ||
UnionIter::new(self) | ||
} | ||
} | ||
|
||
impl<'a> std::iter::ExactSizeIterator for UnionIter<'a> {} | ||
|
||
unsafe impl<'a> TrustedLen for UnionIter<'a> {} |
Oops, something went wrong.