Skip to content
Closed
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
2 changes: 2 additions & 0 deletions encodings/alp/src/alp/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use crate::ALPFloat;
use crate::match_each_alp_float_ptype;

impl OperationsVTable<ALP> for ALP {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, ALP>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/alp/src/alp_rd/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::ALPRDArrayExt;
use crate::ALPRDArraySlotsExt;

impl OperationsVTable<ALPRD> for ALPRD {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, ALPRD>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/bytebool/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ impl ValidityVTable<ByteBool> for ByteBool {
}

impl OperationsVTable<ByteBool> for ByteBool {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, ByteBool>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/datetime-parts/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::timestamp;
use crate::timestamp::TimestampParts;

impl OperationsVTable<DateTimeParts> for DateTimeParts {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, DateTimeParts>,
index: usize,
Expand Down
2 changes: 2 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 @@ -289,6 +289,8 @@ fn to_canonical_decimal(
}

impl OperationsVTable<DecimalByteParts> for DecimalByteParts {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, DecimalByteParts>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/fastlanes/src/bitpacking/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::BitPacked;
use crate::bitpack_decompress;
use crate::bitpacking::array::BitPackedArrayExt;
impl OperationsVTable<BitPacked> for BitPacked {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, BitPacked>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/fastlanes/src/delta/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use vortex_error::VortexResult;

use super::Delta;
impl OperationsVTable<Delta> for Delta {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Delta>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/fastlanes/src/for/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use super::FoR;
use crate::r#for::array::FoRArrayExt;
use crate::r#for::array::FoRArraySlotsExt;
impl OperationsVTable<FoR> for FoR {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, FoR>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/fastlanes/src/rle/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::rle::RLEArrayExt;
use crate::rle::RLEArraySlotsExt;

impl OperationsVTable<RLE> for RLE {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, RLE>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/fastlanes/src/transposed_bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ impl VTable for TransposedBool {
}

impl OperationsVTable<TransposedBool> for TransposedBool {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, TransposedBool>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/fsst/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::FSST;
use crate::FSSTArrayExt;

impl OperationsVTable<FSST> for FSST {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, FSST>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/onpair/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use crate::decode::code_boundary_at;
use crate::decode::collect_widened;

impl OperationsVTable<OnPair> for OnPair {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, OnPair>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/parquet-variant/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use crate::ParquetVariantArraySlotsExt;
use crate::vtable::ParquetVariant;

impl OperationsVTable<ParquetVariant> for ParquetVariant {
type ProbeState = ();

/// Resolves one row according to the Parquet Variant shredding rules.
///
/// For valid data, a row with both `value` and struct `typed_value` is a partially
Expand Down
2 changes: 2 additions & 0 deletions encodings/pco/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ impl ValidityVTable<Pco> for Pco {
}

impl OperationsVTable<Pco> for Pco {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Pco>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/runend/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use crate::array::RunEndArrayExt;
use crate::array::RunEndArraySlotsExt;

impl OperationsVTable<RunEnd> for RunEnd {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, RunEnd>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/sequence/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ impl VTable for Sequence {
}

impl OperationsVTable<Sequence> for Sequence {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Sequence>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/sparse/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::Sparse;
use crate::SparseExt as _;

impl OperationsVTable<Sparse> for Sparse {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Sparse>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/zigzag/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ impl Default for ZigZagData {
}

impl OperationsVTable<ZigZag> for ZigZag {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, ZigZag>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/zstd/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,8 @@ impl ValidityVTable<Zstd> for Zstd {
}

impl OperationsVTable<Zstd> for Zstd {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Zstd>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions encodings/zstd/src/zstd_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ impl VTable for ZstdBuffers {
}

impl OperationsVTable<ZstdBuffers> for ZstdBuffers {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, ZstdBuffers>,
index: usize,
Expand Down
8 changes: 7 additions & 1 deletion vortex-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub use erased::*;

mod plugin;
pub use plugin::*;
mod probe;
pub use probe::*;

mod foreign;
pub(crate) use foreign::*;
Expand Down Expand Up @@ -497,7 +499,11 @@ impl<V: VTable> DynArrayData for ArrayData<V> {
ctx: &mut ExecutionCtx,
) -> VortexResult<Scalar> {
let view = unsafe { ArrayView::new_unchecked(this, &self.data) };
<V::OperationsVTable as OperationsVTable<V>>::scalar_at(view, index, ctx)
<V::OperationsVTable as OperationsVTable<V>>::probe_scalar(
&mut ProbeState::once(view),
index,
ctx,
)
}
}

Expand Down
28 changes: 28 additions & 0 deletions vortex-array/src/array/probe/array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use crate::array::ArrayView;
use crate::array::VTable;

/// Everything an encoding's `probe_scalar` runs with.
///
/// Passed to [`OperationsVTable::probe_scalar`](crate::vtable::OperationsVTable::probe_scalar).
/// Holds the typed view of the array being read; it owns nothing, so building one per read is
/// free.
pub struct ProbeState<'a, V: VTable> {
array: ArrayView<'a, V>,
}

impl<'a, V: VTable> ProbeState<'a, V> {
/// State for a single read of `array`.
#[inline]
pub fn once(array: ArrayView<'a, V>) -> Self {
Self { array }
}

/// The typed view of the array being read.
#[inline]
pub fn array(&self) -> ArrayView<'a, V> {
self.array
}
}
8 changes: 8 additions & 0 deletions vortex-array/src/array/probe/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

//! State passed to an encoding's
//! [`probe_scalar`](crate::vtable::OperationsVTable::probe_scalar).

mod array;
pub use array::*;
26 changes: 26 additions & 0 deletions vortex-array/src/array/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use vortex_error::vortex_bail;
use crate::ExecutionCtx;
use crate::array::ArrayView;
use crate::array::VTable;
use crate::array::probe::ProbeState;
use crate::scalar::Scalar;
use crate::vtable::NotSupported;

Expand All @@ -17,6 +18,29 @@ use crate::vtable::NotSupported;
/// [`ArrayRef`](crate::ArrayRef)
/// methods perform common checks before dispatching here.
pub trait OperationsVTable<V: VTable> {
/// Encoding-specific state retained across repeated scalar reads.
///
/// Built once per retained probe and never for a one-off read. Use `()` when no state is
/// needed.
type ProbeState: Default + 'static;

/// Read the non-null scalar at `index` of the array in `state`.
///
/// Bounds and validity have been checked; the row is non-null. `state` carries the typed
/// view of the array being read. The scalar must retain the source's logical dtype,
/// including nullability.
///
/// The default preserves the existing scalar path.
fn probe_scalar(
state: &mut ProbeState<'_, V>,
index: usize,
ctx: &mut ExecutionCtx,
) -> VortexResult<Scalar> {
// FIXME: Remove this default once all encodings have migrated to probe_scalar.
Self::scalar_at(state.array(), index, ctx)
}

// FIXME: Deprecate scalar_at once encodings have migrated to probe_scalar.
/// Fetch the scalar at the given index.
///
/// ## Preconditions
Expand All @@ -35,6 +59,8 @@ pub trait OperationsVTable<V: VTable> {
}

impl<V: VTable> OperationsVTable<V> for NotSupported {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, V>,
_index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/bool/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::arrays::bool::BoolArrayExt;
use crate::scalar::Scalar;

impl OperationsVTable<Bool> for Bool {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Bool>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/chunked/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::arrays::chunked::ChunkedArrayExt;
use crate::scalar::Scalar;

impl OperationsVTable<Chunked> for Chunked {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Chunked>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/constant/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::arrays::Constant;
use crate::scalar::Scalar;

impl OperationsVTable<Constant> for Constant {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Constant>,
_index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/decimal/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use crate::scalar::DecimalValue;
use crate::scalar::Scalar;

impl OperationsVTable<Decimal> for Decimal {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Decimal>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/dict/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use crate::arrays::dict::DictArraySlotsExt;
use crate::scalar::Scalar;

impl OperationsVTable<Dict> for Dict {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Dict>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/extension/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::arrays::extension::ExtensionArrayExt;
use crate::scalar::Scalar;

impl OperationsVTable<Extension> for Extension {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Extension>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/filter/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ impl VTable for Filter {
}
}
impl OperationsVTable<Filter> for Filter {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Filter>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/fixed_size_list/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::arrays::fixed_size_list::FixedSizeListArrayExt;
use crate::scalar::Scalar;

impl OperationsVTable<FixedSizeList> for FixedSizeList {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, FixedSizeList>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/interleave/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ impl VTable for Interleave {
}

impl OperationsVTable<Interleave> for Interleave {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Interleave>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/list/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::arrays::list::ListArrayExt;
use crate::scalar::Scalar;

impl OperationsVTable<List> for List {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, List>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/listview/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::arrays::listview::ListViewArrayExt;
use crate::scalar::Scalar;

impl OperationsVTable<ListView> for ListView {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, ListView>,
index: usize,
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/arrays/map/vtable/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::arrays::struct_::StructArrayExt;
use crate::scalar::Scalar;

impl OperationsVTable<Map> for Map {
type ProbeState = ();

fn scalar_at(
array: ArrayView<'_, Map>,
index: usize,
Expand Down
Loading
Loading