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
55c3f9c
commit 5c8f646
Showing
31 changed files
with
654 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use crate::array::{Array, MapArray}; | ||
|
||
pub(super) fn equal(lhs: &MapArray, rhs: &MapArray) -> 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
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,41 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::{array::FromFfi, error::Result, ffi}; | ||
|
||
use super::super::{ffi::ToFfi, Array}; | ||
use super::MapArray; | ||
|
||
unsafe impl ToFfi for MapArray { | ||
fn buffers(&self) -> Vec<Option<std::ptr::NonNull<u8>>> { | ||
vec![ | ||
self.validity.as_ref().map(|x| x.as_ptr()), | ||
std::ptr::NonNull::new(self.offsets.as_ptr() as *mut u8), | ||
] | ||
} | ||
|
||
fn offset(&self) -> usize { | ||
self.offset | ||
} | ||
|
||
fn children(&self) -> Vec<Arc<dyn Array>> { | ||
vec![self.field.clone()] | ||
} | ||
} | ||
|
||
impl<A: ffi::ArrowArrayRef> FromFfi<A> for MapArray { | ||
unsafe fn try_from_ffi(array: A) -> Result<Self> { | ||
let data_type = array.field().data_type().clone(); | ||
let length = array.array().len(); | ||
let offset = array.array().offset(); | ||
let mut validity = unsafe { array.validity() }?; | ||
let mut offsets = unsafe { array.buffer::<i32>(0) }?; | ||
let child = array.child(0)?; | ||
let values = ffi::try_from(child)?.into(); | ||
|
||
if offset > 0 { | ||
offsets = offsets.slice(offset, length); | ||
validity = validity.map(|x| x.slice(offset, length)) | ||
} | ||
Ok(Self::from_data(data_type, offsets, values, validity)) | ||
} | ||
} |
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,85 @@ | ||
use crate::array::Array; | ||
use crate::bitmap::utils::{zip_validity, ZipValidity}; | ||
use crate::trusted_len::TrustedLen; | ||
|
||
use super::MapArray; | ||
|
||
/// Iterator of values of an [`ListArray`]. | ||
#[derive(Clone, Debug)] | ||
pub struct MapValuesIter<'a> { | ||
array: &'a MapArray, | ||
index: usize, | ||
end: usize, | ||
} | ||
|
||
impl<'a> MapValuesIter<'a> { | ||
#[inline] | ||
pub fn new(array: &'a MapArray) -> Self { | ||
Self { | ||
array, | ||
index: 0, | ||
end: array.len(), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Iterator for MapValuesIter<'a> { | ||
type Item = Box<dyn Array>; | ||
|
||
#[inline] | ||
fn next(&mut self) -> Option<Self::Item> { | ||
if self.index == self.end { | ||
return None; | ||
} | ||
let old = self.index; | ||
self.index += 1; | ||
// Safety: | ||
// self.end is maximized by the length of the array | ||
Some(unsafe { self.array.value_unchecked(old) }) | ||
} | ||
|
||
#[inline] | ||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
(self.end - self.index, Some(self.end - self.index)) | ||
} | ||
} | ||
|
||
unsafe impl<'a> TrustedLen for MapValuesIter<'a> {} | ||
|
||
impl<'a> DoubleEndedIterator for MapValuesIter<'a> { | ||
#[inline] | ||
fn next_back(&mut self) -> Option<Self::Item> { | ||
if self.index == self.end { | ||
None | ||
} else { | ||
self.end -= 1; | ||
// Safety: | ||
// self.end is maximized by the length of the array | ||
Some(unsafe { self.array.value_unchecked(self.end) }) | ||
} | ||
} | ||
} | ||
|
||
impl<'a> IntoIterator for &'a MapArray { | ||
type Item = Option<Box<dyn Array>>; | ||
type IntoIter = ZipValidity<'a, Box<dyn Array>, MapValuesIter<'a>>; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
self.iter() | ||
} | ||
} | ||
|
||
impl<'a> MapArray { | ||
/// Returns an iterator of `Option<Box<dyn Array>>` | ||
pub fn iter(&'a self) -> ZipValidity<'a, Box<dyn Array>, MapValuesIter<'a>> { | ||
zip_validity( | ||
MapValuesIter::new(self), | ||
self.validity.as_ref().map(|x| x.iter()), | ||
) | ||
} | ||
|
||
/// Returns an iterator of `Box<dyn Array>` | ||
pub fn values_iter(&'a self) -> MapValuesIter<'a> { | ||
MapValuesIter::new(self) | ||
} | ||
} |
Oops, something went wrong.