@@ -9,22 +9,22 @@ use std::hash::Hasher;
99
1010use kernel:: PARENT_KERNELS ;
1111use prost:: Message as _;
12+ use vortex_array:: AnyCanonical ;
1213use vortex_array:: Array ;
1314use vortex_array:: ArrayEq ;
1415use vortex_array:: ArrayHash ;
1516use vortex_array:: ArrayId ;
1617use vortex_array:: ArrayParts ;
17- use vortex_array:: AnyCanonical ;
1818use vortex_array:: ArrayRef ;
1919use vortex_array:: ArrayView ;
2020use vortex_array:: Canonical ;
2121use vortex_array:: ExecutionCtx ;
2222use vortex_array:: ExecutionResult ;
2323use vortex_array:: IntoArray ;
2424use vortex_array:: Precision ;
25- use vortex_array:: arrays:: Primitive ;
2625use vortex_array:: arrays:: BoolArray ;
2726use vortex_array:: arrays:: ConstantArray ;
27+ use vortex_array:: arrays:: Primitive ;
2828use vortex_array:: arrays:: PrimitiveArray ;
2929use vortex_array:: arrays:: bool:: BoolArrayExt ;
3030use vortex_array:: buffer:: BufferHandle ;
@@ -33,6 +33,8 @@ use vortex_array::dtype::DType;
3333use vortex_array:: dtype:: Nullability ;
3434use vortex_array:: patches:: Patches ;
3535use vortex_array:: patches:: PatchesMetadata ;
36+ use vortex_array:: require_child;
37+ use vortex_array:: require_opt_child;
3638use vortex_array:: scalar:: Scalar ;
3739use vortex_array:: scalar:: ScalarValue ;
3840use vortex_array:: scalar_fn:: fns:: operators:: Operator ;
@@ -81,28 +83,6 @@ pub(crate) struct SparseParts {
8183 pub len : usize ,
8284}
8385
84- impl SparseParts {
85- /// Resolve patches by subtracting the offset from indices.
86- pub fn resolve_patches ( mut self ) -> VortexResult < Self > {
87- if self . patches . offset ( ) != 0 {
88- let offset_scalar =
89- Scalar :: from ( self . patches . offset ( ) ) . cast ( self . patches . indices ( ) . dtype ( ) ) ?;
90- let indices = self . patches . indices ( ) . binary (
91- ConstantArray :: new ( offset_scalar, self . patches . indices ( ) . len ( ) ) . into_array ( ) ,
92- Operator :: Sub ,
93- ) ?;
94- self . patches = Patches :: new (
95- self . patches . array_len ( ) ,
96- 0 ,
97- indices,
98- self . patches . values ( ) . clone ( ) ,
99- None ,
100- ) ?;
101- }
102- Ok ( self )
103- }
104- }
105-
10686pub ( crate ) trait SparseOwnedExt {
10787 fn into_parts ( self ) -> VortexResult < SparseParts > ;
10888}
@@ -272,26 +252,49 @@ impl VTable for Sparse {
272252 }
273253
274254 fn execute ( array : Array < Self > , ctx : & mut ExecutionCtx ) -> VortexResult < ExecutionResult > {
255+ // Resolve offset first: wrap indices in Binary(indices, offset, Sub) and rebuild
256+ // with offset=0. Uses slot children (not data) since the executor may have
257+ // updated slots via reduce_parent/execute_parent.
258+ let array = if array. patches ( ) . offset ( ) != 0 {
259+ let offset = array. patches ( ) . offset ( ) ;
260+ let indices = array. patch_indices ( ) ;
261+ let offset_scalar = Scalar :: from ( offset) . cast ( indices. dtype ( ) ) ?;
262+ let resolved_indices = indices. binary (
263+ ConstantArray :: new ( offset_scalar, indices. len ( ) ) . into_array ( ) ,
264+ Operator :: Sub ,
265+ ) ?;
266+ let patches = Patches :: new (
267+ array. len ( ) ,
268+ 0 ,
269+ resolved_indices,
270+ array. patch_values ( ) . clone ( ) ,
271+ None ,
272+ ) ?;
273+ Sparse :: try_new_from_patches ( patches, array. fill_scalar ( ) . clone ( ) ) ?
274+ } else {
275+ array
276+ } ;
277+
275278 // Require children to be executed through the scheduler,
276279 // enabling cross-step optimization via reduce_parent rules.
277- let array = vortex_array :: require_child!(
280+ let array = require_child ! (
278281 array, array. patch_indices( ) , SparseSlots :: PATCH_INDICES => Primitive
279282 ) ;
280- let array = vortex_array :: require_child!(
283+ let array = require_child ! (
281284 array, array. patch_values( ) , SparseSlots :: PATCH_VALUES => AnyCanonical
282285 ) ;
283- vortex_array :: require_opt_child!(
286+ require_opt_child ! (
284287 array,
285288 array. patch_chunk_offsets( ) ,
286289 SparseSlots :: PATCH_CHUNK_OFFSETS => Primitive
287290 ) ;
288291
289- let parts = array. into_parts ( ) ?. resolve_patches ( ) ?;
292+ let parts = array. into_parts ( ) ?;
293+ // TODO(joe): remove ctx from execute_sparse since all slots should be canonical.
290294 execute_sparse ( parts, ctx) . map ( ExecutionResult :: done)
291295 }
292296}
293297
294-
295298#[ derive( Clone , Debug ) ]
296299pub struct SparseData {
297300 patches : Patches ,
0 commit comments