-
Notifications
You must be signed in to change notification settings - Fork 32
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
2b3a96d
commit 7e5fbc7
Showing
2 changed files
with
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,52 @@ | ||
use arrow_buffer::BooleanBuffer; | ||
use num_traits::AsPrimitive; | ||
|
||
use vortex_error::VortexResult; | ||
|
||
use crate::array::bool::BoolArray; | ||
use crate::array::{Array, ArrayRef}; | ||
use crate::compute::flatten::flatten_primitive; | ||
use crate::compute::take::TakeFn; | ||
use vortex_error::VortexResult; | ||
use crate::match_each_integer_ptype; | ||
use crate::validity::ArrayValidity; | ||
|
||
impl TakeFn for BoolArray { | ||
fn take(&self, indices: &dyn Array) -> VortexResult<ArrayRef> { | ||
todo!() | ||
let validity = self.validity().map(|v| v.take(indices)).transpose()?; | ||
let indices = flatten_primitive(indices)?; | ||
match_each_integer_ptype!(indices.ptype(), |$I| { | ||
Ok(BoolArray::from_nullable( | ||
take_bool(self.buffer(), indices.typed_data::<$I>()), | ||
validity, | ||
).into_array()) | ||
}) | ||
} | ||
} | ||
|
||
fn take_bool<I: AsPrimitive<usize>>(bools: &BooleanBuffer, indices: &[I]) -> Vec<bool> { | ||
indices.iter().map(|&idx| bools.value(idx.as_())).collect() | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::array::bool::BoolArray; | ||
use crate::array::downcast::DowncastArrayBuiltin; | ||
use crate::array::primitive::PrimitiveArray; | ||
use crate::compute::take::take; | ||
|
||
#[test] | ||
fn take_nullable() { | ||
let reference = BoolArray::from_iter(vec![ | ||
Some(false), | ||
Some(true), | ||
Some(false), | ||
None, | ||
Some(false), | ||
]); | ||
let res = take(&reference, &PrimitiveArray::from(vec![0, 3, 4])).unwrap(); | ||
assert_eq!( | ||
res.as_bool().buffer(), | ||
BoolArray::from_iter(vec![Some(false), None, Some(false)]).buffer() | ||
); | ||
} | ||
} |
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