Skip to content

Commit

Permalink
Cast Bool (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn authored Mar 4, 2024
1 parent 59dcb79 commit 048db57
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
11 changes: 11 additions & 0 deletions vortex/src/array/bool/compute.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
use crate::array::bool::BoolArray;
use crate::array::Array;
use crate::compute::cast::CastBoolFn;
use crate::compute::scalar_at::ScalarAtFn;
use crate::compute::ArrayCompute;
use crate::error::VortexResult;
use crate::scalar::{NullableScalar, Scalar};

impl ArrayCompute for BoolArray {
fn cast_bool(&self) -> Option<&dyn CastBoolFn> {
Some(self)
}

fn scalar_at(&self) -> Option<&dyn ScalarAtFn> {
Some(self)
}
}

impl CastBoolFn for BoolArray {
fn cast_bool(&self) -> VortexResult<BoolArray> {
Ok(self.clone())
}
}

impl ScalarAtFn for BoolArray {
fn scalar_at(&self, index: usize) -> VortexResult<Box<dyn Scalar>> {
if self.is_valid(index) {
Expand Down
14 changes: 14 additions & 0 deletions vortex/src/compute/cast.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::array::bool::BoolArray;
use crate::array::primitive::PrimitiveArray;
use crate::array::Array;
use crate::error::{VortexError, VortexResult};
Expand All @@ -19,3 +20,16 @@ pub fn cast_primitive(array: &dyn Array, ptype: &PType) -> VortexResult<Primitiv
))
})
}

pub trait CastBoolFn {
fn cast_bool(&self) -> VortexResult<BoolArray>;
}

pub fn cast_bool(array: &dyn Array) -> VortexResult<BoolArray> {
array.cast_bool().map(|t| t.cast_bool()).unwrap_or_else(|| {
Err(VortexError::NotImplemented(
"cast_bool",
array.encoding().id(),
))
})
}
7 changes: 6 additions & 1 deletion vortex/src/compute/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cast::CastPrimitiveFn;
use cast::{CastBoolFn, CastPrimitiveFn};
use patch::PatchFn;
use scalar_at::ScalarAtFn;
use take::TakeFn;
Expand All @@ -13,6 +13,10 @@ pub mod search_sorted;
pub mod take;

pub trait ArrayCompute {
fn cast_bool(&self) -> Option<&dyn CastBoolFn> {
None
}

fn cast_primitive(&self) -> Option<&dyn CastPrimitiveFn> {
None
}
Expand All @@ -24,6 +28,7 @@ pub trait ArrayCompute {
fn scalar_at(&self) -> Option<&dyn ScalarAtFn> {
None
}

fn take(&self) -> Option<&dyn TakeFn> {
None
}
Expand Down

0 comments on commit 048db57

Please sign in to comment.