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
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/alp/src/alp/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use vortex_array::ExecutionCtx;
use vortex_array::Precision;
use vortex_array::ProstMetadata;
use vortex_array::SerializeMetadata;
use vortex_array::VectorExecutor;
use vortex_array::patches::Patches;
use vortex_array::patches::PatchesMetadata;
use vortex_array::serde::ArrayChildren;
Expand Down
11 changes: 11 additions & 0 deletions encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: Copyright the Vortex contributors

mod compute;
mod rules;

use std::hash::Hash;
use std::ops::Range;
Expand Down Expand Up @@ -48,6 +49,8 @@ use vortex_error::vortex_ensure;
use vortex_scalar::DecimalValue;
use vortex_scalar::Scalar;

use crate::decimal_byte_parts::rules::PARENT_RULES;

vtable!(DecimalByteParts);

#[derive(Clone, prost::Message)]
Expand Down Expand Up @@ -127,6 +130,14 @@ impl VTable for DecimalBytePartsVTable {
array.msp = children.into_iter().next().vortex_expect("checked");
Ok(())
}

fn reduce_parent(
array: &Self::Array,
parent: &ArrayRef,
child_idx: usize,
) -> VortexResult<Option<ArrayRef>> {
PARENT_RULES.evaluate(array, parent, child_idx)
}
}

/// This array encodes decimals as between 1-4 columns of primitive typed children.
Expand Down
47 changes: 47 additions & 0 deletions encodings/decimal-byte-parts/src/decimal_byte_parts/rules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use vortex_array::ArrayRef;
use vortex_array::IntoArray;
use vortex_array::arrays::FilterArray;
use vortex_array::arrays::FilterVTable;
use vortex_array::matchers::Exact;
use vortex_array::optimizer::rules::ArrayParentReduceRule;
use vortex_array::optimizer::rules::ParentRuleSet;
use vortex_error::VortexResult;

use crate::DecimalBytePartsArray;
use crate::DecimalBytePartsVTable;

pub(super) const PARENT_RULES: ParentRuleSet<DecimalBytePartsVTable> =
ParentRuleSet::new(&[ParentRuleSet::lift(&DecimalBytePartsFilterPushDownRule)]);

#[derive(Debug)]
struct DecimalBytePartsFilterPushDownRule;

impl ArrayParentReduceRule<DecimalBytePartsVTable> for DecimalBytePartsFilterPushDownRule {
type Parent = Exact<FilterVTable>;

fn parent(&self) -> Self::Parent {
Exact::from(&FilterVTable)
}

fn reduce_parent(
&self,
child: &DecimalBytePartsArray,
parent: &FilterArray,
_child_idx: usize,
) -> VortexResult<Option<ArrayRef>> {
// TODO(ngates): we should benchmark whether to push-down filters with "lower parts".
// For now, we only push down if there are no lower parts.
if !child._lower_parts.is_empty() {
return Ok(None);
}

let new_msp =
FilterArray::new(child.msp.clone(), parent.filter_mask().clone()).into_array();
let new_child =
DecimalBytePartsArray::try_new(new_msp, *child.decimal_dtype())?.into_array();
Ok(Some(new_child))
Comment on lines +29 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think we need this vs just decompressing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we implemented DBP as a scalar function, it would happen via unary filter pushdown. It's kind of important

}
}
1 change: 1 addition & 0 deletions encodings/fastlanes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ prost = { workspace = true }
rand = { workspace = true, optional = true }
vortex-array = { workspace = true }
vortex-buffer = { workspace = true }
vortex-compute = { workspace = true }
vortex-dtype = { workspace = true }
vortex-error = { workspace = true }
vortex-mask = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions encodings/fastlanes/src/delta/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use prost::Message;
use vortex_array::ArrayRef;
use vortex_array::ExecutionCtx;
use vortex_array::ProstMetadata;
use vortex_array::VectorExecutor;
use vortex_array::serde::ArrayChildren;
use vortex_array::vtable;
use vortex_array::vtable::ArrayId;
Expand Down
10 changes: 10 additions & 0 deletions encodings/fastlanes/src/for/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ use vortex_scalar::Scalar;
use vortex_scalar::ScalarValue;

use crate::FoRArray;
use crate::r#for::vtable::rules::PARENT_RULES;

mod array;
mod canonical;
mod encode;
mod operations;
mod rules;
mod validity;
mod visitor;

Expand Down Expand Up @@ -104,6 +106,14 @@ impl VTable for FoRVTable {

FoRArray::try_new(encoded, reference)
}

fn reduce_parent(
array: &Self::Array,
parent: &ArrayRef,
child_idx: usize,
) -> VortexResult<Option<ArrayRef>> {
PARENT_RULES.evaluate(array, parent, child_idx)
}
}

#[derive(Debug)]
Expand Down
44 changes: 44 additions & 0 deletions encodings/fastlanes/src/for/vtable/rules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use vortex_array::ArrayRef;
use vortex_array::IntoArray;
use vortex_array::arrays::FilterArray;
use vortex_array::arrays::FilterVTable;
use vortex_array::matchers::Exact;
use vortex_array::optimizer::rules::ArrayParentReduceRule;
use vortex_array::optimizer::rules::ParentRuleSet;
use vortex_error::VortexResult;

use crate::FoRArray;
use crate::FoRVTable;

pub(super) const PARENT_RULES: ParentRuleSet<FoRVTable> =
ParentRuleSet::new(&[ParentRuleSet::lift(&FoRFilterPushDownRule)]);

#[derive(Debug)]
struct FoRFilterPushDownRule;

impl ArrayParentReduceRule<FoRVTable> for FoRFilterPushDownRule {
type Parent = Exact<FilterVTable>;

fn parent(&self) -> Self::Parent {
Exact::from(&FilterVTable)
}

fn reduce_parent(
&self,
child: &FoRArray,
parent: &FilterArray,
_child_idx: usize,
) -> VortexResult<Option<ArrayRef>> {
let new_array = unsafe {
FoRArray::new_unchecked(
FilterArray::new(child.encoded().clone(), parent.filter_mask().clone())
.into_array(),
child.reference.clone(),
)
};
Ok(Some(new_array.into_array()))
}
}
57 changes: 44 additions & 13 deletions encodings/sequence/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::hash::Hash;
use std::ops::Range;

use num_traits::One;
use num_traits::cast::FromPrimitive;
use vortex_array::ArrayBufferVisitor;
use vortex_array::ArrayChildVisitor;
Expand All @@ -15,6 +14,7 @@ use vortex_array::ExecutionCtx;
use vortex_array::Precision;
use vortex_array::ProstMetadata;
use vortex_array::SerializeMetadata;
use vortex_array::arrays::FilterVTable;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::serde::ArrayChildren;
use vortex_array::stats::ArrayStats;
Expand Down Expand Up @@ -45,11 +45,14 @@ use vortex_error::VortexResult;
use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_err;
use vortex_mask::AllOr;
use vortex_mask::Mask;
use vortex_scalar::PValue;
use vortex_scalar::Scalar;
use vortex_scalar::ScalarValue;
use vortex_vector::Vector;
use vortex_vector::VectorMut;
use vortex_vector::VectorMutOps;
use vortex_vector::primitive::PVector;

vtable!(Sequence);
Expand Down Expand Up @@ -285,20 +288,48 @@ impl VTable for SequenceVTable {
let base = array.base().cast::<P>();
let multiplier = array.multiplier().cast::<P>();

let values = if multiplier == <P>::one() {
BufferMut::from_iter(
(0..array.len()).map(|i| base + <P>::from_usize(i).vortex_expect("must fit")),
)
} else {
BufferMut::from_iter(
(0..array.len())
.map(|i| base + <P>::from_usize(i).vortex_expect("must fit") * multiplier),
)
};

PVector::<P>::new(values.freeze(), Mask::new_true(array.len())).into()
execute_iter(base, multiplier, 0..array.len(), array.len()).into()
}))
}

fn execute_parent(
array: &Self::Array,
parent: &ArrayRef,
_child_idx: usize,
_ctx: &mut ExecutionCtx,
) -> VortexResult<Option<Vector>> {
// Special-case filtered execution.
let Some(filter) = parent.as_opt::<FilterVTable>() else {
return Ok(None);
};

match filter.filter_mask().indices() {
AllOr::All => Ok(None),
AllOr::None => Ok(Some(VectorMut::with_capacity(array.dtype(), 0).freeze())),
AllOr::Some(indices) => Ok(Some(match_each_native_ptype!(array.ptype(), |P| {
let base = array.base().cast::<P>();
let multiplier = array.multiplier().cast::<P>();
execute_iter(base, multiplier, indices.iter().copied(), indices.len()).into()
}))),
}
}
}

fn execute_iter<P: NativePType, I: Iterator<Item = usize>>(
base: P,
multiplier: P,
iter: I,
len: usize,
) -> PVector<P> {
let values = if multiplier == <P>::one() {
BufferMut::from_iter(iter.map(|i| base + <P>::from_usize(i).vortex_expect("must fit")))
} else {
BufferMut::from_iter(
iter.map(|i| base + <P>::from_usize(i).vortex_expect("must fit") * multiplier),
)
};

PVector::<P>::new(values.freeze(), Mask::new_true(len))
}

impl BaseArrayVTable<SequenceVTable> for SequenceVTable {
Expand Down
32 changes: 0 additions & 32 deletions vortex-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ use vortex_error::vortex_err;
use vortex_error::vortex_panic;
use vortex_mask::Mask;
use vortex_scalar::Scalar;
use vortex_vector::Vector;
use vortex_vector::VectorOps;
use vortex_vector::vector_matches_dtype;

use crate::ArrayEq;
use crate::ArrayHash;
Expand All @@ -52,7 +49,6 @@ use crate::compute::InvocationArgs;
use crate::compute::IsConstantOpts;
use crate::compute::Output;
use crate::compute::is_constant_opts;
use crate::executor::ExecutionCtx;
use crate::expr::stats::Precision;
use crate::expr::stats::Stat;
use crate::expr::stats::StatsProviderExt;
Expand Down Expand Up @@ -200,11 +196,6 @@ pub trait Array:
/// call.
fn invoke(&self, compute_fn: &ComputeFn, args: &InvocationArgs)
-> VortexResult<Option<Output>>;

/// Recursively execute an array using batch CPU execution.
///
/// To invoke the top-level execution, see [`crate::executor::VectorExecutor`].
fn execute(&self, ctx: &mut ExecutionCtx) -> VortexResult<Vector>;
}

impl Array for Arc<dyn Array> {
Expand Down Expand Up @@ -318,10 +309,6 @@ impl Array for Arc<dyn Array> {
) -> VortexResult<Option<Output>> {
self.as_ref().invoke(compute_fn, args)
}

fn execute(&self, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
self.as_ref().execute(ctx)
}
}

/// A reference counted pointer to a dynamic [`Array`] trait object.
Expand Down Expand Up @@ -679,25 +666,6 @@ impl<V: VTable> Array for ArrayAdapter<V> {
) -> VortexResult<Option<Output>> {
<V::ComputeVTable as ComputeVTable<V>>::invoke(&self.0, compute_fn, args)
}

fn execute(&self, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
let result = V::execute(&self.0, ctx)?;

if cfg!(debug_assertions) {
vortex_ensure!(
result.len() == self.len(),
"Result length mismatch for {}",
self.encoding_id()
);
vortex_ensure!(
vector_matches_dtype(&result, self.dtype()),
"Executed vector dtype mismatch for {}",
self.encoding_id()
);
}

Ok(result)
}
}

impl<V: VTable> ArrayHash for ArrayAdapter<V> {
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/bool/vtable/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::arrays::BoolArray;
use crate::arrays::BoolVTable;
use crate::arrays::MaskedArray;
use crate::arrays::MaskedVTable;
use crate::matchers::Exact;
use crate::optimizer::rules::ArrayParentReduceRule;
use crate::optimizer::rules::Exact;
use crate::optimizer::rules::ParentRuleSet;
use crate::vtable::ValidityHelper;

Expand Down
1 change: 1 addition & 0 deletions vortex-array/src/arrays/chunked/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::Canonical;
use crate::EmptyMetadata;
use crate::IntoArray;
use crate::ToCanonical;
use crate::VectorExecutor;
use crate::arrays::ChunkedArray;
use crate::arrays::PrimitiveArray;
use crate::executor::ExecutionCtx;
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/constant/vtable/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::arrays::ConstantArray;
use crate::arrays::ConstantVTable;
use crate::arrays::FilterArray;
use crate::arrays::FilterVTable;
use crate::matchers::Exact;
use crate::optimizer::rules::ArrayParentReduceRule;
use crate::optimizer::rules::Exact;
use crate::optimizer::rules::ParentRuleSet;

pub(super) const PARENT_RULES: ParentRuleSet<ConstantVTable> =
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/decimal/vtable/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::arrays::DecimalArray;
use crate::arrays::DecimalVTable;
use crate::arrays::MaskedArray;
use crate::arrays::MaskedVTable;
use crate::matchers::Exact;
use crate::optimizer::rules::ArrayParentReduceRule;
use crate::optimizer::rules::Exact;
use crate::optimizer::rules::ParentRuleSet;
use crate::vtable::ValidityHelper;

Expand Down
1 change: 1 addition & 0 deletions vortex-array/src/arrays/dict/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::ArrayRef;
use crate::DeserializeMetadata;
use crate::ProstMetadata;
use crate::SerializeMetadata;
use crate::VectorExecutor;
use crate::executor::ExecutionCtx;
use crate::serde::ArrayChildren;
use crate::vtable;
Expand Down
1 change: 1 addition & 0 deletions vortex-array/src/arrays/extension/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use vortex_vector::Vector;

use crate::ArrayRef;
use crate::EmptyMetadata;
use crate::VectorExecutor;
use crate::arrays::extension::ExtensionArray;
use crate::executor::ExecutionCtx;
use crate::serde::ArrayChildren;
Expand Down
Loading
Loading