Skip to content
Draft
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions encodings/bytebool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ num-traits = { workspace = true }
vortex-array = { workspace = true }
vortex-buffer = { workspace = true }
vortex-error = { workspace = true }
vortex-mask = { workspace = true }
vortex-session = { workspace = true }

[dev-dependencies]
Expand Down
4 changes: 4 additions & 0 deletions encodings/bytebool/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ impl vortex_array::arrays::dict::take::TakeExecute for vortex_bytebool::ByteBool

pub fn vortex_bytebool::ByteBool::take(array: &vortex_bytebool::ByteBoolArray, indices: &vortex_array::array::ArrayRef, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>

impl vortex_array::arrays::filter::kernel::FilterReduce for vortex_bytebool::ByteBool

pub fn vortex_bytebool::ByteBool::filter(array: &vortex_bytebool::ByteBoolArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>

impl vortex_array::arrays::slice::SliceReduce for vortex_bytebool::ByteBool

pub fn vortex_bytebool::ByteBool::slice(array: &vortex_bytebool::ByteBoolArray, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
Expand Down
2 changes: 2 additions & 0 deletions encodings/bytebool/src/rules.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use vortex_array::arrays::filter::FilterReduceAdaptor;
use vortex_array::arrays::slice::SliceReduceAdaptor;
use vortex_array::optimizer::rules::ParentRuleSet;
use vortex_array::scalar_fn::fns::cast::CastReduceAdaptor;
Expand All @@ -12,4 +13,5 @@ pub(crate) static RULES: ParentRuleSet<ByteBool> = ParentRuleSet::new(&[
ParentRuleSet::lift(&CastReduceAdaptor(ByteBool)),
ParentRuleSet::lift(&MaskReduceAdaptor(ByteBool)),
ParentRuleSet::lift(&SliceReduceAdaptor(ByteBool)),
ParentRuleSet::lift(&FilterReduceAdaptor(ByteBool)),
]);
20 changes: 20 additions & 0 deletions encodings/bytebool/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use std::ops::Range;

use vortex_array::ArrayRef;
use vortex_array::IntoArray;
use vortex_array::arrays::filter::FilterReduce;
use vortex_array::arrays::slice::SliceReduce;
use vortex_array::vtable::ValidityHelper;
use vortex_error::VortexResult;
use vortex_mask::Mask;

use crate::ByteBool;
use crate::ByteBoolArray;
Expand All @@ -23,3 +25,21 @@ impl SliceReduce for ByteBool {
))
}
}

impl FilterReduce for ByteBool {
fn filter(array: &ByteBoolArray, mask: &Mask) -> VortexResult<Option<ArrayRef>> {
let ranges: Vec<Range<usize>> = mask
.slices()
.unwrap_or_else(|| unreachable!(), || unreachable!())
.iter()
.map(|&(s, e)| s..e)
.collect();
Ok(Some(
ByteBoolArray::new(
array.buffer().filter_typed::<u8>(&ranges)?,
array.validity().filter(mask)?,
)
.into_array(),
))
}
}
48 changes: 48 additions & 0 deletions vortex-array/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,10 @@ impl vortex_array::arrays::dict::TakeExecute for vortex_array::arrays::Decimal

pub fn vortex_array::arrays::Decimal::take(array: &vortex_array::arrays::DecimalArray, indices: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::Decimal

pub fn vortex_array::arrays::Decimal::filter(array: &vortex_array::arrays::DecimalArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::slice::SliceReduce for vortex_array::arrays::Decimal

pub fn vortex_array::arrays::Decimal::slice(array: &Self::Array, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
Expand Down Expand Up @@ -2386,14 +2390,30 @@ impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::Consta

pub fn vortex_array::arrays::Constant::filter(array: &vortex_array::arrays::ConstantArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::Decimal

pub fn vortex_array::arrays::Decimal::filter(array: &vortex_array::arrays::DecimalArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::Extension

pub fn vortex_array::arrays::Extension::filter(array: &vortex_array::arrays::ExtensionArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::FixedSizeList

pub fn vortex_array::arrays::FixedSizeList::filter(array: &vortex_array::arrays::FixedSizeListArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::Masked

pub fn vortex_array::arrays::Masked::filter(array: &vortex_array::arrays::MaskedArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::Primitive

pub fn vortex_array::arrays::Primitive::filter(array: &vortex_array::arrays::PrimitiveArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::VarBinView

pub fn vortex_array::arrays::VarBinView::filter(array: &vortex_array::arrays::VarBinViewArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::dict::Dict

pub fn vortex_array::arrays::dict::Dict::filter(array: &vortex_array::arrays::dict::DictArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
Expand All @@ -2418,6 +2438,10 @@ impl vortex_array::arrays::dict::TakeExecute for vortex_array::arrays::FixedSize

pub fn vortex_array::arrays::FixedSizeList::take(array: &vortex_array::arrays::FixedSizeListArray, indices: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::FixedSizeList

pub fn vortex_array::arrays::FixedSizeList::filter(array: &vortex_array::arrays::FixedSizeListArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::slice::SliceReduce for vortex_array::arrays::FixedSizeList

pub fn vortex_array::arrays::FixedSizeList::slice(array: &Self::Array, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
Expand Down Expand Up @@ -3256,6 +3280,10 @@ impl vortex_array::arrays::dict::TakeExecute for vortex_array::arrays::Primitive

pub fn vortex_array::arrays::Primitive::take(array: &vortex_array::arrays::PrimitiveArray, indices: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::Primitive

pub fn vortex_array::arrays::Primitive::filter(array: &vortex_array::arrays::PrimitiveArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::slice::SliceReduce for vortex_array::arrays::Primitive

pub fn vortex_array::arrays::Primitive::slice(array: &Self::Array, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
Expand Down Expand Up @@ -4662,6 +4690,10 @@ impl vortex_array::arrays::dict::TakeExecute for vortex_array::arrays::VarBinVie

pub fn vortex_array::arrays::VarBinView::take(array: &vortex_array::arrays::VarBinViewArray, indices: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::VarBinView

pub fn vortex_array::arrays::VarBinView::filter(array: &vortex_array::arrays::VarBinViewArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::slice::SliceReduce for vortex_array::arrays::VarBinView

pub fn vortex_array::arrays::VarBinView::slice(array: &Self::Array, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
Expand Down Expand Up @@ -5478,6 +5510,10 @@ impl vortex_array::arrays::dict::TakeExecute for vortex_array::arrays::Decimal

pub fn vortex_array::arrays::Decimal::take(array: &vortex_array::arrays::DecimalArray, indices: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::Decimal

pub fn vortex_array::arrays::Decimal::filter(array: &vortex_array::arrays::DecimalArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::slice::SliceReduce for vortex_array::arrays::Decimal

pub fn vortex_array::arrays::Decimal::slice(array: &Self::Array, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
Expand Down Expand Up @@ -6096,6 +6132,10 @@ impl vortex_array::arrays::dict::TakeExecute for vortex_array::arrays::FixedSize

pub fn vortex_array::arrays::FixedSizeList::take(array: &vortex_array::arrays::FixedSizeListArray, indices: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::FixedSizeList

pub fn vortex_array::arrays::FixedSizeList::filter(array: &vortex_array::arrays::FixedSizeListArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::slice::SliceReduce for vortex_array::arrays::FixedSizeList

pub fn vortex_array::arrays::FixedSizeList::slice(array: &Self::Array, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
Expand Down Expand Up @@ -6818,6 +6858,10 @@ impl vortex_array::arrays::dict::TakeExecute for vortex_array::arrays::Primitive

pub fn vortex_array::arrays::Primitive::take(array: &vortex_array::arrays::PrimitiveArray, indices: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::Primitive

pub fn vortex_array::arrays::Primitive::filter(array: &vortex_array::arrays::PrimitiveArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::slice::SliceReduce for vortex_array::arrays::Primitive

pub fn vortex_array::arrays::Primitive::slice(array: &Self::Array, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
Expand Down Expand Up @@ -7854,6 +7898,10 @@ impl vortex_array::arrays::dict::TakeExecute for vortex_array::arrays::VarBinVie

pub fn vortex_array::arrays::VarBinView::take(array: &vortex_array::arrays::VarBinViewArray, indices: &vortex_array::ArrayRef, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::filter::FilterReduce for vortex_array::arrays::VarBinView

pub fn vortex_array::arrays::VarBinView::filter(array: &vortex_array::arrays::VarBinViewArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

impl vortex_array::arrays::slice::SliceReduce for vortex_array::arrays::VarBinView

pub fn vortex_array::arrays::VarBinView::slice(array: &Self::Array, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
Expand Down
29 changes: 29 additions & 0 deletions vortex-array/src/arrays/decimal/compute/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
use std::ops::Range;

use vortex_error::VortexResult;
use vortex_mask::Mask;

use crate::ArrayRef;
use crate::IntoArray;
use crate::arrays::Decimal;
use crate::arrays::DecimalArray;
use crate::arrays::Masked;
use crate::arrays::MaskedArray;
use crate::arrays::filter::FilterReduce;
use crate::arrays::filter::FilterReduceAdaptor;
use crate::arrays::slice::SliceReduce;
use crate::arrays::slice::SliceReduceAdaptor;
use crate::match_each_decimal_value_type;
Expand All @@ -23,6 +26,7 @@ pub(crate) static RULES: ParentRuleSet<Decimal> = ParentRuleSet::new(&[
ParentRuleSet::lift(&DecimalMaskedValidityRule),
ParentRuleSet::lift(&MaskReduceAdaptor(Decimal)),
ParentRuleSet::lift(&SliceReduceAdaptor(Decimal)),
ParentRuleSet::lift(&FilterReduceAdaptor(Decimal)),
]);

/// Rule to push down validity masking from MaskedArray parent into DecimalArray child.
Expand Down Expand Up @@ -72,3 +76,28 @@ impl SliceReduce for Decimal {
Ok(Some(result))
}
}

impl FilterReduce for Decimal {
fn filter(array: &DecimalArray, mask: &Mask) -> VortexResult<Option<ArrayRef>> {
let ranges: Vec<Range<usize>> = mask
.slices()
.unwrap_or_else(|| unreachable!(), || unreachable!())
.iter()
.map(|&(s, e)| s..e)
.collect();
let result = match_each_decimal_value_type!(array.values_type(), |D| {
// SAFETY: Filtering preserves all DecimalArray invariants — values within
// precision bounds remain valid, and we correctly filter the validity.
unsafe {
DecimalArray::new_unchecked_handle(
array.buffer_handle().filter_typed::<D>(&ranges)?,
array.values_type(),
array.decimal_dtype(),
array.validity().filter(mask)?,
)
}
.into_array()
});
Ok(Some(result))
}
}
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/fixed_size_list/compute/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use crate::arrays::FixedSizeList;
use crate::arrays::filter::FilterReduceAdaptor;
use crate::arrays::slice::SliceReduceAdaptor;
use crate::optimizer::rules::ParentRuleSet;
use crate::scalar_fn::fns::cast::CastReduceAdaptor;
Expand All @@ -11,4 +12,5 @@ pub(crate) const PARENT_RULES: ParentRuleSet<FixedSizeList> = ParentRuleSet::new
ParentRuleSet::lift(&CastReduceAdaptor(FixedSizeList)),
ParentRuleSet::lift(&MaskReduceAdaptor(FixedSizeList)),
ParentRuleSet::lift(&SliceReduceAdaptor(FixedSizeList)),
ParentRuleSet::lift(&FilterReduceAdaptor(FixedSizeList)),
]);
38 changes: 38 additions & 0 deletions vortex-array/src/arrays/fixed_size_list/compute/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
use std::ops::Range;

use vortex_error::VortexResult;
use vortex_mask::Mask;

use crate::ArrayRef;
use crate::IntoArray;
use crate::arrays::FixedSizeList;
use crate::arrays::FixedSizeListArray;
use crate::arrays::filter::FilterReduce;
use crate::arrays::slice::SliceReduce;
use crate::vtable::ValidityHelper;

Expand All @@ -33,3 +35,39 @@ impl SliceReduce for FixedSizeList {
))
}
}

impl FilterReduce for FixedSizeList {
fn filter(array: &FixedSizeListArray, mask: &Mask) -> VortexResult<Option<ArrayRef>> {
let list_size = array.list_size() as usize;
let new_len = mask.true_count();

let filtered_elements = if list_size == 0 {
// Degenerate case: elements array is empty regardless of filter.
array.elements().clone()
} else {
let elements_len = array.elements().len();
let expanded_slices: Vec<(usize, usize)> = mask
.slices()
.unwrap_or_else(|| unreachable!(), || unreachable!())
.iter()
.map(|&(s, e)| (s * list_size, e * list_size))
.collect();
let elements_mask = Mask::from_slices(elements_len, expanded_slices);
array.elements().filter(elements_mask)?
};

// SAFETY: Filtering preserves FixedSizeListArray invariants — each selected list's
// elements are contiguously preserved, maintaining elements.len() == new_len * list_size.
Ok(Some(
unsafe {
FixedSizeListArray::new_unchecked(
filtered_elements,
array.list_size(),
array.validity().filter(mask)?,
new_len,
)
}
.into_array(),
))
}
}
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/primitive/compute/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::arrays::Masked;
use crate::arrays::MaskedArray;
use crate::arrays::Primitive;
use crate::arrays::PrimitiveArray;
use crate::arrays::filter::FilterReduceAdaptor;
use crate::arrays::slice::SliceReduceAdaptor;
use crate::optimizer::rules::ArrayParentReduceRule;
use crate::optimizer::rules::ParentRuleSet;
Expand All @@ -19,6 +20,7 @@ pub(crate) const RULES: ParentRuleSet<Primitive> = ParentRuleSet::new(&[
ParentRuleSet::lift(&PrimitiveMaskedValidityRule),
ParentRuleSet::lift(&MaskReduceAdaptor(Primitive)),
ParentRuleSet::lift(&SliceReduceAdaptor(Primitive)),
ParentRuleSet::lift(&FilterReduceAdaptor(Primitive)),
]);

/// Rule to push down validity masking from MaskedArray parent into PrimitiveArray child.
Expand Down
22 changes: 22 additions & 0 deletions vortex-array/src/arrays/primitive/compute/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
use std::ops::Range;

use vortex_error::VortexResult;
use vortex_mask::Mask;

use crate::ArrayRef;
use crate::IntoArray;
use crate::arrays::Primitive;
use crate::arrays::PrimitiveArray;
use crate::arrays::filter::FilterReduce;
use crate::arrays::slice::SliceReduce;
use crate::dtype::NativePType;
use crate::match_each_native_ptype;
Expand All @@ -27,3 +29,23 @@ impl SliceReduce for Primitive {
Ok(Some(result))
}
}

impl FilterReduce for Primitive {
fn filter(array: &PrimitiveArray, mask: &Mask) -> VortexResult<Option<ArrayRef>> {
let ranges: Vec<Range<usize>> = mask
.slices()
.unwrap_or_else(|| unreachable!(), || unreachable!())
.iter()
.map(|&(s, e)| s..e)
.collect();
let result = match_each_native_ptype!(array.ptype(), |T| {
PrimitiveArray::from_buffer_handle(
array.buffer_handle().filter_typed::<T>(&ranges)?,
T::PTYPE,
array.validity().filter(mask)?,
)
.into_array()
});
Ok(Some(result))
}
}
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/varbinview/compute/rules.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use crate::arrays::VarBinView;
use crate::arrays::filter::FilterReduceAdaptor;
use crate::arrays::slice::SliceReduceAdaptor;
use crate::optimizer::rules::ParentRuleSet;
use crate::scalar_fn::fns::cast::CastReduceAdaptor;
Expand All @@ -10,4 +11,5 @@ pub(crate) const PARENT_RULES: ParentRuleSet<VarBinView> = ParentRuleSet::new(&[
ParentRuleSet::lift(&CastReduceAdaptor(VarBinView)),
ParentRuleSet::lift(&MaskReduceAdaptor(VarBinView)),
ParentRuleSet::lift(&SliceReduceAdaptor(VarBinView)),
ParentRuleSet::lift(&FilterReduceAdaptor(VarBinView)),
]);
Loading
Loading