Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement filter for dict #1099

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion encodings/dict/src/compute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use vortex::compute::unary::{scalar_at, scalar_at_unchecked, ScalarAtFn};
use vortex::compute::{slice, take, ArrayCompute, SliceFn, TakeFn};
use vortex::compute::{filter, slice, take, ArrayCompute, FilterFn, SliceFn, TakeFn};
use vortex::{Array, IntoArray};
use vortex_error::{VortexExpect, VortexResult};
use vortex_scalar::Scalar;
Expand All @@ -18,6 +18,10 @@ impl ArrayCompute for DictArray {
fn take(&self) -> Option<&dyn TakeFn> {
Some(self)
}

fn filter(&self) -> Option<&dyn FilterFn> {
Some(self)
}
}

impl ScalarAtFn for DictArray {
Expand Down Expand Up @@ -46,6 +50,13 @@ impl TakeFn for DictArray {
}
}

impl FilterFn for DictArray {
fn filter(&self, predicate: &Array) -> VortexResult<Array> {
let codes = filter(self.codes(), predicate)?;
Self::try_new(codes, self.values()).map(|a| a.into_array())
}
}

impl SliceFn for DictArray {
// TODO(robert): Add function to trim the dictionary
fn slice(&self, start: usize, stop: usize) -> VortexResult<Array> {
Expand Down
Loading