Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions vortex-compute/src/filter/bitbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ use crate::filter::Filter;
// TODO(ngates): we need more experimentation to determine the best threshold here.
const FILTER_SLICES_DENSITY_THRESHOLD: f64 = 0.8;

impl Filter for BitBuffer {
fn filter(&self, mask: &Mask) -> Self {
impl Filter for &BitBuffer {
type Output = BitBuffer;

fn filter(self, mask: &Mask) -> BitBuffer {
assert_eq!(mask.len(), self.len());
match mask {
Mask::AllTrue(_) => self.clone(),
Mask::AllFalse(_) => Self::empty(),
Mask::AllFalse(_) => BitBuffer::empty(),
Mask::Values(v) => match v.threshold_iter(FILTER_SLICES_DENSITY_THRESHOLD) {
MaskIter::Indices(indices) => filter_indices(self, indices),
MaskIter::Slices(slices) => filter_slices(self, mask.true_count(), slices),
Expand Down
8 changes: 5 additions & 3 deletions vortex-compute/src/filter/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ use vortex_vector::bool::BoolVector;

use crate::filter::Filter;

impl Filter for BoolVector {
fn filter(&self, mask: &Mask) -> Self {
impl Filter for &BoolVector {
type Output = BoolVector;

fn filter(self, mask: &Mask) -> BoolVector {
let filtered_bits = self.bits().filter(mask);
let filtered_validity = self.validity().filter(mask);

// SAFETY: We filter the bits and validity with the same mask, and since they came from an
// existing and valid `BoolVector`, we know that the filtered output must have the same
// length.
unsafe { Self::new_unchecked(filtered_bits, filtered_validity) }
unsafe { BoolVector::new_unchecked(filtered_bits, filtered_validity) }
}
}
8 changes: 5 additions & 3 deletions vortex-compute/src/filter/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use crate::filter::Filter;
// This is modeled after the constant with the equivalent name in arrow-rs.
const FILTER_SLICES_SELECTIVITY_THRESHOLD: f64 = 0.8;

impl<T: Copy> Filter for Buffer<T> {
fn filter(&self, mask: &Mask) -> Self {
impl<T: Copy> Filter for &Buffer<T> {
type Output = Buffer<T>;

fn filter(self, mask: &Mask) -> Buffer<T> {
assert_eq!(mask.len(), self.len());
match mask {
Mask::AllTrue(_) => self.clone(),
Mask::AllFalse(_) => Self::empty(),
Mask::AllFalse(_) => Buffer::empty(),
Mask::Values(v) => match v.threshold_iter(FILTER_SLICES_SELECTIVITY_THRESHOLD) {
MaskIter::Indices(indices) => filter_indices(self.as_slice(), indices),
MaskIter::Slices(slices) => {
Expand Down
8 changes: 5 additions & 3 deletions vortex-compute/src/filter/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ use vortex_mask::Mask;

use crate::filter::Filter;

impl Filter for Mask {
fn filter(&self, mask: &Mask) -> Self {
impl Filter for &Mask {
type Output = Mask;

fn filter(self, mask: &Mask) -> Mask {
assert_eq!(self.len(), mask.len());

match (self, mask) {
(Mask::AllTrue(_), _) => Mask::AllTrue(mask.true_count()),
(Mask::AllFalse(_), _) => Mask::AllFalse(mask.true_count()),

(Mask::Values(_), Mask::AllTrue(_)) => self.clone(),
(Mask::Values(_), Mask::AllFalse(_)) => Self::new_true(0),
(Mask::Values(_), Mask::AllFalse(_)) => Mask::new_true(0),
(Mask::Values(v1), Mask::Values(_)) => Mask::from(v1.bit_buffer().filter(mask)),
}
}
Expand Down
5 changes: 4 additions & 1 deletion vortex-compute/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ use vortex_mask::Mask;

/// Function for filtering based on a selection mask.
pub trait Filter {
/// The result type after performing the operation.
type Output;

/// Filters the vector using the provided mask, returning a new value.
///
/// The result value will have length equal to the true count of the provided mask.
///
/// # Panics
///
/// If the length of the mask does not equal the length of the value being filtered.
fn filter(&self, mask: &Mask) -> Self;
fn filter(self, mask: &Mask) -> Self::Output;
}
Loading