-
Notifications
You must be signed in to change notification settings - Fork 31
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
Showing
6 changed files
with
145 additions
and
97 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use vortex_array::compute::{fill_null, FillNullFn}; | ||
use vortex_array::{ArrayData, ArrayLen, IntoArrayData}; | ||
use vortex_error::VortexResult; | ||
use vortex_scalar::Scalar; | ||
|
||
use crate::{RunEndArray, RunEndEncoding}; | ||
|
||
impl FillNullFn<RunEndArray> for RunEndEncoding { | ||
fn fill_null(&self, array: &RunEndArray, fill_value: Scalar) -> VortexResult<ArrayData> { | ||
Ok(RunEndArray::with_offset_and_length( | ||
array.ends(), | ||
fill_null(array.values(), fill_value)?, | ||
array.len(), | ||
array.offset(), | ||
)? | ||
.into_array()) | ||
} | ||
} |
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,103 @@ | ||
use vortex_array::array::PrimitiveArray; | ||
use vortex_array::compute::{take, TakeFn}; | ||
use vortex_array::variants::PrimitiveArrayTrait; | ||
use vortex_array::{ArrayData, ArrayLen, IntoArrayData, IntoArrayVariant}; | ||
use vortex_dtype::match_each_integer_ptype; | ||
use vortex_error::VortexResult; | ||
|
||
use crate::{RunEndArray, RunEndEncoding}; | ||
|
||
impl TakeFn<RunEndArray> for RunEndEncoding { | ||
#[allow(deprecated)] | ||
fn take(&self, array: &RunEndArray, indices: &ArrayData) -> VortexResult<ArrayData> { | ||
let primitive_indices = indices.clone().into_primitive()?; | ||
let usize_indices = match_each_integer_ptype!(primitive_indices.ptype(), |$P| { | ||
primitive_indices | ||
.into_maybe_null_slice::<$P>() | ||
.into_iter() | ||
.map(|idx| { | ||
let usize_idx = idx as usize; | ||
if usize_idx >= array.len() { | ||
vortex_error::vortex_bail!(OutOfBounds: usize_idx, 0, array.len()); | ||
} | ||
|
||
Ok(usize_idx + array.offset()) | ||
}) | ||
.collect::<VortexResult<Vec<usize>>>()? | ||
}); | ||
let physical_indices = array | ||
.find_physical_indices(&usize_indices)? | ||
.into_iter() | ||
.map(|idx| idx as u64) | ||
.collect::<Vec<_>>(); | ||
let physical_indices_array = PrimitiveArray::from(physical_indices).into_array(); | ||
take(array.values(), &physical_indices_array) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use vortex_array::array::PrimitiveArray; | ||
use vortex_array::compute::{scalar_at, slice, take}; | ||
use vortex_array::{IntoArrayVariant, ToArrayData}; | ||
|
||
use crate::RunEndArray; | ||
|
||
pub(crate) fn ree_array() -> RunEndArray { | ||
RunEndArray::encode( | ||
PrimitiveArray::from(vec![1, 1, 1, 4, 4, 4, 2, 2, 5, 5, 5, 5]).to_array(), | ||
) | ||
.unwrap() | ||
} | ||
|
||
#[test] | ||
fn ree_take() { | ||
let taken = take( | ||
ree_array().as_ref(), | ||
PrimitiveArray::from(vec![9, 8, 1, 3]).as_ref(), | ||
) | ||
.unwrap(); | ||
assert_eq!( | ||
taken.into_primitive().unwrap().maybe_null_slice::<i32>(), | ||
&[5, 5, 1, 4] | ||
); | ||
} | ||
|
||
#[test] | ||
fn ree_take_end() { | ||
let taken = take( | ||
ree_array().as_ref(), | ||
PrimitiveArray::from(vec![11]).as_ref(), | ||
) | ||
.unwrap(); | ||
assert_eq!( | ||
taken.into_primitive().unwrap().maybe_null_slice::<i32>(), | ||
&[5] | ||
); | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn ree_take_out_of_bounds() { | ||
take( | ||
ree_array().as_ref(), | ||
PrimitiveArray::from(vec![12]).as_ref(), | ||
) | ||
.unwrap(); | ||
} | ||
|
||
#[test] | ||
fn sliced_take() { | ||
let sliced = slice(ree_array().as_ref(), 4, 9).unwrap(); | ||
let taken = take( | ||
sliced.as_ref(), | ||
PrimitiveArray::from(vec![1, 3, 4]).as_ref(), | ||
) | ||
.unwrap(); | ||
|
||
assert_eq!(taken.len(), 3); | ||
assert_eq!(scalar_at(taken.as_ref(), 0).unwrap(), 4.into()); | ||
assert_eq!(scalar_at(taken.as_ref(), 1).unwrap(), 2.into()); | ||
assert_eq!(scalar_at(taken.as_ref(), 2).unwrap(), 5.into()); | ||
} | ||
} |
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