@@ -42,8 +42,8 @@ use vortex_array::validity::Validity;
4242use vortex_array:: vtable;
4343use vortex_array:: vtable:: OperationsVTable ;
4444use vortex_array:: vtable:: VTable ;
45- use vortex_array:: vtable:: ValiditySliceHelper ;
46- use vortex_array:: vtable:: ValidityVTableFromValiditySliceHelper ;
45+ use vortex_array:: vtable:: ValidityVTable ;
46+ use vortex_array:: vtable:: child_to_validity ;
4747use vortex_array:: vtable:: validity_to_child;
4848use vortex_buffer:: BufferMut ;
4949use vortex_buffer:: ByteBuffer ;
@@ -83,7 +83,6 @@ vtable!(Pco, Pco, PcoData);
8383
8484impl ArrayHash for PcoData {
8585 fn array_hash < H : Hasher > ( & self , state : & mut H , precision : Precision ) {
86- self . unsliced_validity . array_hash ( state, precision) ;
8786 self . unsliced_n_rows . hash ( state) ;
8887 self . slice_start . hash ( state) ;
8988 self . slice_stop . hash ( state) ;
@@ -99,10 +98,7 @@ impl ArrayHash for PcoData {
9998
10099impl ArrayEq for PcoData {
101100 fn array_eq ( & self , other : & Self , precision : Precision ) -> bool {
102- if !self
103- . unsliced_validity
104- . array_eq ( & other. unsliced_validity , precision)
105- || self . unsliced_n_rows != other. unsliced_n_rows
101+ if self . unsliced_n_rows != other. unsliced_n_rows
106102 || self . slice_start != other. slice_start
107103 || self . slice_stop != other. slice_stop
108104 || self . chunk_metas . len ( ) != other. chunk_metas . len ( )
@@ -128,7 +124,7 @@ impl VTable for Pco {
128124 type ArrayData = PcoData ;
129125
130126 type OperationsVTable = Self ;
131- type ValidityVTable = ValidityVTableFromValiditySliceHelper ;
127+ type ValidityVTable = Self ;
132128
133129 fn id ( & self ) -> ArrayId {
134130 Self :: ID
@@ -139,9 +135,10 @@ impl VTable for Pco {
139135 data : & PcoData ,
140136 dtype : & DType ,
141137 len : usize ,
142- _slots : & [ Option < ArrayRef > ] ,
138+ slots : & [ Option < ArrayRef > ] ,
143139 ) -> VortexResult < ( ) > {
144- data. validate ( dtype, len)
140+ let validity = child_to_validity ( & slots[ 0 ] , dtype. nullability ( ) ) ;
141+ data. validate ( dtype, len, & validity)
145142 }
146143
147144 fn nbuffers ( array : ArrayView < ' _ , Self > ) -> usize {
@@ -206,14 +203,7 @@ impl VTable for Pco {
206203 vortex_ensure ! ( pages. len( ) == expected_n_pages) ;
207204
208205 let slots = vec ! [ validity_to_child( & validity, len) ] ;
209- let data = PcoData :: new (
210- chunk_metas,
211- pages,
212- dtype. as_ptype ( ) ,
213- metadata,
214- len,
215- validity,
216- ) ;
206+ let data = PcoData :: new ( chunk_metas, pages, dtype. as_ptype ( ) , metadata, len) ;
217207 Ok ( ArrayParts :: new ( self . clone ( ) , dtype. clone ( ) , len, data) . with_slots ( slots) )
218208 }
219209
@@ -222,7 +212,14 @@ impl VTable for Pco {
222212 }
223213
224214 fn execute ( array : Array < Self > , ctx : & mut ExecutionCtx ) -> VortexResult < ExecutionResult > {
225- Ok ( ExecutionResult :: done ( array. decompress ( ctx) ?. into_array ( ) ) )
215+ let unsliced_validity =
216+ child_to_validity ( & array. as_ref ( ) . slots ( ) [ 0 ] , array. dtype ( ) . nullability ( ) ) ;
217+ Ok ( ExecutionResult :: done (
218+ array
219+ . data ( )
220+ . decompress ( & unsliced_validity, ctx) ?
221+ . into_array ( ) ,
222+ ) )
226223 }
227224
228225 fn reduce_parent (
@@ -273,13 +270,14 @@ pub struct Pco;
273270impl Pco {
274271 pub const ID : ArrayId = ArrayId :: new_ref ( "vortex.pco" ) ;
275272
276- pub ( crate ) fn try_new ( dtype : DType , data : PcoData ) -> VortexResult < PcoArray > {
273+ pub ( crate ) fn try_new (
274+ dtype : DType ,
275+ data : PcoData ,
276+ validity : Validity ,
277+ ) -> VortexResult < PcoArray > {
277278 let len = data. len ( ) ;
278- data. validate ( & dtype, len) ?;
279- let slots = vec ! [ validity_to_child(
280- & data. unsliced_validity,
281- data. unsliced_n_rows,
282- ) ] ;
279+ data. validate ( & dtype, len, & validity) ?;
280+ let slots = vec ! [ validity_to_child( & validity, data. unsliced_n_rows( ) ) ] ;
283281 Ok ( unsafe {
284282 Array :: from_parts_unchecked ( ArrayParts :: new ( Pco , dtype, len, data) . with_slots ( slots) )
285283 } )
@@ -292,8 +290,9 @@ impl Pco {
292290 values_per_page : usize ,
293291 ) -> VortexResult < PcoArray > {
294292 let dtype = parray. dtype ( ) . clone ( ) ;
293+ let validity = parray. validity ( ) ?;
295294 let data = PcoData :: from_primitive ( parray, level, values_per_page) ?;
296- Self :: try_new ( dtype, data)
295+ Self :: try_new ( dtype, data, validity )
297296 }
298297}
299298
@@ -307,14 +306,13 @@ pub struct PcoData {
307306 pub ( crate ) pages : Vec < ByteBuffer > ,
308307 pub ( crate ) metadata : PcoMetadata ,
309308 ptype : PType ,
310- pub ( crate ) unsliced_validity : Validity ,
311309 unsliced_n_rows : usize ,
312310 slice_start : usize ,
313311 slice_stop : usize ,
314312}
315313
316314impl PcoData {
317- pub fn validate ( & self , dtype : & DType , len : usize ) -> VortexResult < ( ) > {
315+ pub fn validate ( & self , dtype : & DType , len : usize , validity : & Validity ) -> VortexResult < ( ) > {
318316 let _ = number_type_from_ptype ( self . ptype ) ;
319317 vortex_ensure ! (
320318 dtype. as_ptype( ) == self . ptype,
@@ -323,9 +321,9 @@ impl PcoData {
323321 dtype. as_ptype( )
324322 ) ;
325323 vortex_ensure ! (
326- dtype. nullability( ) == self . unsliced_validity . nullability( ) ,
324+ dtype. nullability( ) == validity . nullability( ) ,
327325 "expected nullability {}, got {}" ,
328- self . unsliced_validity . nullability( ) ,
326+ validity . nullability( ) ,
329327 dtype. nullability( )
330328 ) ;
331329 vortex_ensure ! (
@@ -340,7 +338,7 @@ impl PcoData {
340338 "expected len {len}, got {}" ,
341339 self . slice_stop - self . slice_start
342340 ) ;
343- if let Some ( validity_len) = self . unsliced_validity . maybe_len ( ) {
341+ if let Some ( validity_len) = validity . maybe_len ( ) {
344342 vortex_ensure ! (
345343 validity_len == self . unsliced_n_rows,
346344 "expected validity len {}, got {}" ,
@@ -373,14 +371,12 @@ impl PcoData {
373371 ptype : PType ,
374372 metadata : PcoMetadata ,
375373 len : usize ,
376- validity : Validity ,
377374 ) -> Self {
378375 Self {
379376 chunk_metas,
380377 pages,
381378 metadata,
382379 ptype,
383- unsliced_validity : validity,
384380 unsliced_n_rows : len,
385381 slice_start : 0 ,
386382 slice_stop : len,
@@ -464,7 +460,6 @@ impl PcoData {
464460 parray. dtype ( ) . as_ptype ( ) ,
465461 metadata,
466462 parray. len ( ) ,
467- parray. validity ( ) ?,
468463 ) )
469464 }
470465
@@ -478,33 +473,36 @@ impl PcoData {
478473 Self :: from_primitive ( & parray, level, nums_per_page)
479474 }
480475
481- pub fn decompress ( & self , ctx : & mut ExecutionCtx ) -> VortexResult < PrimitiveArray > {
476+ pub fn decompress (
477+ & self ,
478+ unsliced_validity : & Validity ,
479+ ctx : & mut ExecutionCtx ,
480+ ) -> VortexResult < PrimitiveArray > {
482481 // To start, we figure out which chunks and pages we need to decompress, and with
483482 // what value offset into the first such page.
484483 let number_type = number_type_from_ptype ( self . ptype ) ;
485484 let values_byte_buffer = match_number_enum ! (
486485 number_type,
487486 NumberType <T > => {
488- self . decompress_values_typed:: <T >( ctx) ?
487+ self . decompress_values_typed:: <T >( unsliced_validity , ctx) ?
489488 }
490489 ) ;
491490
492491 Ok ( PrimitiveArray :: from_values_byte_buffer (
493492 values_byte_buffer,
494493 self . ptype ,
495- self . unsliced_validity
496- . slice ( self . slice_start ..self . slice_stop ) ?,
494+ unsliced_validity. slice ( self . slice_start ..self . slice_stop ) ?,
497495 self . slice_stop - self . slice_start ,
498496 ) )
499497 }
500498
501499 fn decompress_values_typed < T : Number > (
502500 & self ,
501+ unsliced_validity : & Validity ,
503502 ctx : & mut ExecutionCtx ,
504503 ) -> VortexResult < ByteBuffer > {
505504 // To start, we figure out what range of values we need to decompress.
506- let slice_value_indices = self
507- . unsliced_validity
505+ let slice_value_indices = unsliced_validity
508506 . execute_mask ( self . unsliced_n_rows , ctx) ?
509507 . valid_counts_for_indices ( & [ self . slice_start , self . slice_stop ] ) ;
510508 let slice_value_start = slice_value_indices[ 0 ] ;
@@ -605,9 +603,10 @@ impl PcoData {
605603 }
606604}
607605
608- impl ValiditySliceHelper for PcoData {
609- fn unsliced_validity_and_slice ( & self ) -> ( & Validity , usize , usize ) {
610- ( & self . unsliced_validity , self . slice_start , self . slice_stop )
606+ impl ValidityVTable < Pco > for Pco {
607+ fn validity ( array : ArrayView < ' _ , Pco > ) -> VortexResult < Validity > {
608+ let unsliced_validity = child_to_validity ( & array. slots ( ) [ 0 ] , array. dtype ( ) . nullability ( ) ) ;
609+ unsliced_validity. slice ( array. slice_start ( ) ..array. slice_stop ( ) )
611610 }
612611}
613612
@@ -618,9 +617,10 @@ impl OperationsVTable<Pco> for Pco {
618617 _ctx : & mut ExecutionCtx ,
619618 ) -> VortexResult < Scalar > {
620619 let mut ctx = LEGACY_SESSION . create_execution_ctx ( ) ;
620+ let unsliced_validity = child_to_validity ( & array. slots ( ) [ 0 ] , array. dtype ( ) . nullability ( ) ) ;
621621 array
622622 . _slice ( index, index + 1 )
623- . decompress ( & mut ctx) ?
623+ . decompress ( & unsliced_validity , & mut ctx) ?
624624 . into_array ( )
625625 . scalar_at ( 0 )
626626 }
0 commit comments