Skip to content

Commit 42dee18

Browse files
committed
merge
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 8eca341 commit 42dee18

File tree

13 files changed

+55
-323
lines changed

13 files changed

+55
-323
lines changed

encodings/alp/src/alp/operator.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use crate::{match_each_alp_float_ptype, ALPArray, ALPFloat, ALPVTable, Exponents};
54
use std::marker::PhantomData;
5+
66
use vortex_array::pipeline::{BindContext, PipelineTransform, TransformKernel};
77
use vortex_array::vtable::{OperatorVTable, PipelineNode};
88
use vortex_buffer::Buffer;
9-
use vortex_dtype::{match_each_integer_ptype, NativePType, PTypeDowncastExt};
9+
use vortex_dtype::{NativePType, PTypeDowncastExt, match_each_integer_ptype};
1010
use vortex_error::VortexResult;
1111
use vortex_vector::primitive::PVector;
1212
use vortex_vector::{Vector, VectorMut};
1313

14+
use crate::{ALPArray, ALPFloat, ALPVTable, Exponents, match_each_alp_float_ptype};
15+
1416
impl OperatorVTable<ALPVTable> for ALPVTable {
1517
fn pipeline_node(array: &ALPArray) -> Option<PipelineNode<'_>> {
1618
Some(PipelineNode::Transform(array))
@@ -40,7 +42,7 @@ impl PipelineTransform for ALPArray {
4042

4143
match_each_alp_float_ptype!(self.ptype(), |A| {
4244
match_each_integer_ptype!(patches.indices_ptype(), |P| {
43-
let patch_indices: Buffer<P> = P::downcast(patch_idxs).into_buffer();
45+
let patch_indices: Buffer<P> = patch_idxs.downcast::<P>().into_elements();
4446
let patch_values: PVector<A> = A::downcast(patch_vals);
4547
Ok(Box::new(PatchedALPKernel {
4648
exponents,
@@ -61,10 +63,10 @@ struct ALPKernel<A: ALPFloat> {
6163
}
6264

6365
impl<A: ALPFloat> TransformKernel for ALPKernel<A> {
64-
fn step(&mut self, input: &VectorMut, out: &mut VectorMut) -> VortexResult<()> {
65-
let encoded = input.into_primitive().downcast::<A::ALPInt>().into_buffer();
66+
fn step(&mut self, input: &Vector, out: &mut VectorMut) -> VortexResult<()> {
67+
let encoded = input.as_primitive().downcast::<A::ALPInt>().elements();
6668

67-
let mut decoded = A::downcast(out.into_primitive());
69+
let decoded = out.as_primitive_mut().downcast::<A>();
6870
decoded.extend(
6971
encoded
7072
.iter()
@@ -74,6 +76,7 @@ impl<A: ALPFloat> TransformKernel for ALPKernel<A> {
7476
}
7577
}
7678

79+
#[allow(dead_code)] // TODO(ngates): implement patching
7780
struct PatchedALPKernel<A: ALPFloat, P: NativePType> {
7881
// The ALP exponents
7982
exponents: Exponents,
@@ -84,9 +87,9 @@ struct PatchedALPKernel<A: ALPFloat, P: NativePType> {
8487

8588
impl<A: ALPFloat, P: NativePType> TransformKernel for PatchedALPKernel<A, P> {
8689
fn step(&mut self, input: &Vector, out: &mut VectorMut) -> VortexResult<()> {
87-
let encoded = input.into_primitive().downcast::<A::ALPInt>().into_buffer();
90+
let encoded = input.as_primitive().downcast::<A::ALPInt>().elements();
8891

89-
let mut decoded = out.into_primitive().downcast::<A>();
92+
let decoded = out.as_primitive_mut().downcast::<A>();
9093
decoded.extend(
9194
encoded
9295
.iter()

encodings/sequence/src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl VTable for SequenceVTable {
160160
type ComputeVTable = NotSupported;
161161
type EncodeVTable = Self;
162162
type SerdeVTable = Self;
163-
type OperatorVTable = Self;
163+
type OperatorVTable = NotSupported;
164164

165165
fn id(_encoding: &Self::Encoding) -> EncodingId {
166166
EncodingId::new_ref("vortex.sequence")

encodings/sequence/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
mod array;
55
mod compress;
66
mod compute;
7-
mod operator;
7+
// mod operator;
88
mod serde;
99

1010
/// Represents the equation A\[i\] = a * i + b.

vortex-array/src/array/operator.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use std::sync::Arc;
55

66
use vortex_error::{VortexResult, vortex_panic};
7-
use vortex_mask::Mask;
87
use vortex_vector::{Vector, VectorOps, vector_matches_dtype};
98

109
use crate::execution::{BatchKernelRef, BindCtx, DummyExecutionCtx, ExecutionCtx};
@@ -17,13 +16,12 @@ use crate::{Array, ArrayAdapter, ArrayRef};
1716
/// Note: the public functions such as "execute" should move onto the main `Array` trait when
1817
/// operators is stabilized. The other functions should remain on a `pub(crate)` trait.
1918
pub trait ArrayOperator: 'static + Send + Sync {
20-
/// Execute the array's batch kernel with the given selection mask.
19+
/// Execute the array's batch kernel.
2120
///
2221
/// # Panics
2322
///
24-
/// If the mask length does not match the array length.
2523
/// If the array's implementation returns an invalid vector (wrong length, wrong type, etc.).
26-
fn execute_batch(&self, selection: &Mask, ctx: &mut dyn ExecutionCtx) -> VortexResult<Vector>;
24+
fn execute_batch(&self, ctx: &mut dyn ExecutionCtx) -> VortexResult<Vector>;
2725

2826
/// Optimize the array by running the optimization rules.
2927
fn reduce_children(&self) -> VortexResult<Option<ArrayRef>>;
@@ -40,8 +38,8 @@ pub trait ArrayOperator: 'static + Send + Sync {
4038
}
4139

4240
impl ArrayOperator for Arc<dyn Array> {
43-
fn execute_batch(&self, selection: &Mask, ctx: &mut dyn ExecutionCtx) -> VortexResult<Vector> {
44-
self.as_ref().execute_batch(selection, ctx)
41+
fn execute_batch(&self, ctx: &mut dyn ExecutionCtx) -> VortexResult<Vector> {
42+
self.as_ref().execute_batch(ctx)
4543
}
4644

4745
fn reduce_children(&self) -> VortexResult<Option<ArrayRef>> {
@@ -62,23 +60,22 @@ impl ArrayOperator for Arc<dyn Array> {
6260
}
6361

6462
impl<V: VTable> ArrayOperator for ArrayAdapter<V> {
65-
fn execute_batch(&self, selection: &Mask, ctx: &mut dyn ExecutionCtx) -> VortexResult<Vector> {
63+
fn execute_batch(&self, ctx: &mut dyn ExecutionCtx) -> VortexResult<Vector> {
6664
// Check if the array is a pipeline node
6765
if let Some(pipeline_node) =
6866
<V::OperatorVTable as OperatorVTable<V>>::pipeline_node(&self.0)
6967
&& let PipelineNode::Source(source) = pipeline_node
7068
{
71-
return PipelineSourceDriver::new(source).execute(selection);
69+
return PipelineSourceDriver::new(source).execute();
7270
}
7371

74-
let vector =
75-
<V::OperatorVTable as OperatorVTable<V>>::execute_batch(&self.0, selection, ctx)?;
72+
let vector = <V::OperatorVTable as OperatorVTable<V>>::execute_batch(&self.0, ctx)?;
7673

7774
// Such a cheap check that we run it always. More expensive DType checks live in
7875
// debug_assertions.
7976
assert_eq!(
8077
vector.len(),
81-
selection.true_count(),
78+
self.len(),
8279
"Batch execution returned vector of incorrect length"
8380
);
8481

@@ -126,11 +123,6 @@ impl BindCtx for () {
126123

127124
impl dyn Array + '_ {
128125
pub fn execute(&self) -> VortexResult<Vector> {
129-
self.execute_batch(&Mask::new_true(self.len()), &mut DummyExecutionCtx)
130-
}
131-
132-
pub fn execute_with_selection(&self, mask: &Mask) -> VortexResult<Vector> {
133-
assert_eq!(self.len(), mask.len());
134-
self.execute_batch(mask, &mut DummyExecutionCtx)
126+
self.execute_batch(&mut DummyExecutionCtx)
135127
}
136128
}

vortex-array/src/arrays/listview/vtable/operator.rs

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ mod tests {
4747
use vortex_mask::Mask;
4848
use vortex_vector::VectorOps;
4949

50-
use crate::IntoArray;
51-
use crate::arrays::listview::tests::common::{
52-
create_basic_listview, create_nullable_listview, create_overlapping_listview,
53-
};
54-
use crate::arrays::{ListViewArray, PrimitiveArray};
55-
use crate::validity::Validity;
50+
use crate::arrays::listview::tests::common::create_basic_listview;
5651

5752
#[test]
5853
fn test_listview_operator_basic() {
@@ -85,106 +80,4 @@ mod tests {
8580
// Verify validity is all valid.
8681
assert!(matches!(listview_vector.validity(), Mask::AllTrue(_)));
8782
}
88-
89-
#[test]
90-
fn test_listview_operator_with_selection() {
91-
// Create a ListView with 6 lists: [[10,11], [20,21], [30,31], [40,41], [50,51], [60,61]]
92-
let elements =
93-
PrimitiveArray::from_iter([10i32, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61])
94-
.into_array();
95-
let offsets = PrimitiveArray::from_iter([0u32, 2, 4, 6, 8, 10]).into_array();
96-
let sizes = PrimitiveArray::from_iter([2u32, 2, 2, 2, 2, 2]).into_array();
97-
let listview = ListViewArray::new(elements, offsets, sizes, Validity::AllValid);
98-
99-
// Create selection mask: [true, false, true, false, true, false].
100-
let selection = Mask::from_iter([true, false, true, false, true, false]);
101-
102-
// Execute with selection.
103-
let result = listview.execute_with_selection(&selection).unwrap();
104-
105-
// Verify filtered length (3 lists selected).
106-
assert_eq!(result.len(), 3);
107-
108-
let listview_vector = result.as_list();
109-
110-
// Verify offsets are filtered to indices 0, 2, 4.
111-
let offsets = listview_vector.offsets().clone().into_u32();
112-
assert_eq!(offsets.elements().as_slice(), &[0, 4, 8]);
113-
114-
// Verify sizes are filtered to indices 0, 2, 4.
115-
let sizes = listview_vector.sizes().clone().into_u32();
116-
assert_eq!(sizes.elements().as_slice(), &[2, 2, 2]);
117-
118-
// Verify elements remain complete (not filtered).
119-
let elements = listview_vector.elements().as_primitive().clone().into_i32();
120-
assert_eq!(
121-
elements.elements().as_slice(),
122-
&[10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61]
123-
);
124-
}
125-
126-
#[test]
127-
fn test_listview_operator_with_nulls_and_selection() {
128-
// Use the nullable listview: [[10,20], null, [50]]
129-
let listview = create_nullable_listview();
130-
131-
// Create selection mask: [true, true, false].
132-
let selection = Mask::from_iter([true, true, false]);
133-
134-
// Execute with selection.
135-
let result = listview.execute_with_selection(&selection).unwrap();
136-
137-
// Verify filtered length (2 lists selected, including the null).
138-
assert_eq!(result.len(), 2);
139-
140-
let listview_vector = result.as_list();
141-
142-
// Verify offsets are filtered to indices 0 and 1.
143-
let offsets = listview_vector.offsets().clone().into_u32();
144-
assert_eq!(offsets.elements().as_slice(), &[0, 2]);
145-
146-
// Verify sizes are filtered to indices 0 and 1.
147-
let sizes = listview_vector.sizes().clone().into_u32();
148-
assert_eq!(sizes.elements().as_slice(), &[2, 2]);
149-
150-
// Verify validity mask correctly shows first list valid, second list null.
151-
assert!(listview_vector.validity().value(0)); // First list is valid.
152-
assert!(!listview_vector.validity().value(1)); // Second list is null.
153-
154-
// Verify elements remain complete.
155-
let elements = listview_vector.elements().as_primitive().clone().into_i32();
156-
assert_eq!(elements.elements().as_slice(), &[10, 20, 30, 40, 50]);
157-
}
158-
159-
#[test]
160-
fn test_listview_operator_overlapping_with_selection() {
161-
// Use the overlapping listview: [[5,6,7], [2,3], [8,9], [0,1], [1,2,3,4]]
162-
let listview = create_overlapping_listview();
163-
164-
// Create selection mask: [true, false, true, true, false].
165-
let selection = Mask::from_iter([true, false, true, true, false]);
166-
167-
// Execute with selection.
168-
let result = listview.execute_with_selection(&selection).unwrap();
169-
170-
// Verify filtered length (3 lists selected).
171-
assert_eq!(result.len(), 3);
172-
173-
let listview_vector = result.as_list();
174-
175-
// Verify offsets are filtered to indices 0, 2, 3 (out-of-order preserved).
176-
let offsets = listview_vector.offsets().clone().into_u32();
177-
assert_eq!(offsets.elements().as_slice(), &[5, 8, 0]);
178-
179-
// Verify sizes are filtered.
180-
let sizes = listview_vector.sizes().clone().into_u32();
181-
assert_eq!(sizes.elements().as_slice(), &[3, 2, 2]);
182-
183-
// Verify elements remain complete (all 10 elements).
184-
let elements = listview_vector.elements().as_primitive().clone().into_i32();
185-
assert_eq!(
186-
elements.elements().as_slice(),
187-
&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
188-
);
189-
}
19083
}

vortex-array/src/arrays/struct_/vtable/operator.rs

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl OperatorVTable<StructVTable> for StructVTable {
4141

4242
#[cfg(test)]
4343
mod tests {
44+
use vortex_buffer::bitbuffer;
4445
use vortex_dtype::{FieldNames, PTypeDowncast};
45-
use vortex_mask::Mask;
4646
use vortex_vector::VectorOps;
4747

4848
use crate::IntoArray;
@@ -82,44 +82,6 @@ mod tests {
8282
assert_eq!(bool_values, vec![true, false, true, false, true]);
8383
}
8484

85-
#[test]
86-
fn test_struct_operator_with_mask() {
87-
// Create a struct array with two fields.
88-
let int_field = PrimitiveArray::from_iter([10i32, 20, 30, 40, 50, 60]);
89-
let bool_field = BoolArray::from_iter([true, false, true, false, true, false]);
90-
91-
let struct_array = StructArray::try_new(
92-
FieldNames::from(["numbers", "flags"]),
93-
vec![int_field.into_array(), bool_field.into_array()],
94-
6,
95-
Validity::AllValid,
96-
)
97-
.unwrap();
98-
99-
// Create a selection mask that selects indices 0, 2, 4 (alternating pattern).
100-
let selection = Mask::from_iter([true, false, true, false, true, false]);
101-
102-
// Execute with selection mask.
103-
let result = struct_array.execute_with_selection(&selection).unwrap();
104-
105-
// Verify the result has the filtered length.
106-
assert_eq!(result.len(), 3);
107-
108-
// Verify the struct vector fields.
109-
let struct_vector = result.as_struct();
110-
let fields = struct_vector.fields();
111-
assert_eq!(fields.len(), 2);
112-
113-
// Verify the integer field has the correct filtered values (indices 0, 2, 4).
114-
let int_vector = fields[0].as_primitive().clone().into_i32();
115-
assert_eq!(int_vector.elements().as_slice(), &[10, 30, 50]);
116-
117-
// Verify the boolean field has the correct filtered values (indices 0, 2, 4).
118-
let bool_vector = fields[1].as_bool();
119-
let bool_values: Vec<bool> = (0..3).map(|i| bool_vector.bits().value(i)).collect();
120-
assert_eq!(bool_values, vec![true, true, true]);
121-
}
122-
12385
#[test]
12486
fn test_struct_operator_null_handling() {
12587
// Create fields with nulls.
@@ -148,13 +110,9 @@ mod tests {
148110
)
149111
.unwrap();
150112

151-
// Create a selection mask that selects indices 0, 1, 2, 4, 5.
152-
let selection = Mask::from_iter([true, true, true, false, true, true]);
153-
154-
// Execute with selection mask.
155-
let result = struct_array.execute_with_selection(&selection).unwrap();
113+
let result = struct_array.execute().unwrap();
156114

157-
assert_eq!(result.len(), 5);
115+
assert_eq!(result.len(), 6);
158116

159117
// Verify the struct vector fields.
160118
let struct_vector = result.as_struct();
@@ -164,23 +122,19 @@ mod tests {
164122
// Verify integer field has the correct filtered values with nulls.
165123
// Selected indices: 0, 1, 2, 4, 5 from [Some(100), None, Some(200), Some(300), None, Some(400)].
166124
let int_vector = fields[0].as_primitive().clone().into_i32();
167-
let int_values: Vec<Option<i32>> = (0..5).map(|i| int_vector.get(i).copied()).collect();
125+
let int_values: Vec<Option<i32>> = (0..6).map(|i| int_vector.get(i).copied()).collect();
168126
assert_eq!(
169127
int_values,
170-
vec![Some(100), None, Some(200), None, Some(400)]
128+
vec![Some(100), None, Some(200), Some(300), None, Some(400)]
171129
);
172130

173-
// Verify boolean field values.
174-
// Selected indices: 0, 1, 2, 4, 5 from [T, F, T, F, T, F].
131+
// Verify boolean field values from [T, F, T, F, T, F].
175132
let bool_vector = fields[1].as_bool();
176-
let bool_values: Vec<bool> = (0..5).map(|i| bool_vector.bits().value(i)).collect();
177-
assert_eq!(bool_values, vec![true, false, true, true, false]);
133+
assert_eq!(bool_vector.bits(), &bitbuffer![1 0 1 0 1 0]);
178134

179135
// Verify the struct-level validity is correctly propagated.
180136
// Original struct validity: [T, F, T, T, F, T]
181-
// Selected indices: 0, 1, 2, 4, 5 -> validity: [T, F, T, F, T].
182137
let validity_mask = struct_vector.validity();
183-
let struct_validity_values: Vec<bool> = (0..5).map(|i| validity_mask.value(i)).collect();
184-
assert_eq!(struct_validity_values, vec![true, false, true, false, true]);
138+
assert_eq!(validity_mask.to_bit_buffer(), bitbuffer![1 0 1 1 0 1]);
185139
}
186140
}

0 commit comments

Comments
 (0)