@@ -9,8 +9,8 @@ use vortex_array::arrays::PrimitiveArray;
99use vortex_array:: stats:: { ArrayStats , StatsSetRef } ;
1010use vortex_array:: validity:: Validity ;
1111use vortex_array:: vtable:: {
12- ArrayVTable , CanonicalVTable , NotSupported , VTable , ValidityHelper ,
13- ValidityVTableFromValidityHelper ,
12+ ArrayVTable , CanonicalVTable , NotSupported , VTable , ValidityChildSliceHelper ,
13+ ValidityVTableFromChildSliceHelper ,
1414} ;
1515use vortex_array:: { Array , ArrayRef , Canonical , EncodingId , EncodingRef , IntoArray , vtable} ;
1616use vortex_buffer:: Buffer ;
@@ -31,7 +31,7 @@ impl VTable for DeltaVTable {
3131 type ArrayVTable = Self ;
3232 type CanonicalVTable = Self ;
3333 type OperationsVTable = Self ;
34- type ValidityVTable = ValidityVTableFromValidityHelper ;
34+ type ValidityVTable = ValidityVTableFromChildSliceHelper ;
3535 type VisitorVTable = Self ;
3636 type ComputeVTable = NotSupported ;
3737 type EncodeVTable = NotSupported ;
@@ -47,20 +47,6 @@ impl VTable for DeltaVTable {
4747 }
4848}
4949
50- #[ derive( Clone , Debug ) ]
51- pub struct DeltaArray {
52- offset : usize ,
53- len : usize ,
54- dtype : DType ,
55- bases : ArrayRef ,
56- deltas : ArrayRef ,
57- validity : Validity ,
58- stats_set : ArrayStats ,
59- }
60-
61- #[ derive( Clone , Debug ) ]
62- pub struct DeltaEncoding ;
63-
6450/// A FastLanes-style delta-encoded array of primitive values.
6551///
6652/// A [`DeltaArray`] comprises a sequence of _chunks_ each representing 1,024 delta-encoded values,
@@ -93,6 +79,21 @@ pub struct DeltaEncoding;
9379///
9480/// If the chunk physically has fewer than 1,024 values, then it is stored as a traditional,
9581/// non-SIMD-amenable, delta-encoded vector.
82+ ///
83+ /// Note the validity is stored in the deltas array.
84+ #[ derive( Clone , Debug ) ]
85+ pub struct DeltaArray {
86+ offset : usize ,
87+ len : usize ,
88+ dtype : DType ,
89+ bases : ArrayRef ,
90+ deltas : ArrayRef ,
91+ stats_set : ArrayStats ,
92+ }
93+
94+ #[ derive( Clone , Debug ) ]
95+ pub struct DeltaEncoding ;
96+
9697impl DeltaArray {
9798 // TODO(ngates): remove constructing from vec
9899 pub fn try_from_vec < T : NativePType > ( vec : Vec < T > ) -> VortexResult < Self > {
@@ -105,26 +106,19 @@ impl DeltaArray {
105106 pub fn try_from_primitive_array ( array : & PrimitiveArray ) -> VortexResult < Self > {
106107 let ( bases, deltas) = delta_compress ( array) ?;
107108
108- Self :: try_from_delta_compress_parts (
109- bases. into_array ( ) ,
110- deltas. into_array ( ) ,
111- Validity :: NonNullable ,
112- )
109+ Self :: try_from_delta_compress_parts ( bases. into_array ( ) , deltas. into_array ( ) )
113110 }
114111
115- pub fn try_from_delta_compress_parts (
116- bases : ArrayRef ,
117- deltas : ArrayRef ,
118- validity : Validity ,
119- ) -> VortexResult < Self > {
112+ /// Create a [`DeltaArray`] from the given `bases` and `deltas` arrays.
113+ /// Note the `deltas` might be nullable
114+ pub fn try_from_delta_compress_parts ( bases : ArrayRef , deltas : ArrayRef ) -> VortexResult < Self > {
120115 let logical_len = deltas. len ( ) ;
121- Self :: try_new ( bases, deltas, validity , 0 , logical_len)
116+ Self :: try_new ( bases, deltas, 0 , logical_len)
122117 }
123118
124119 pub fn try_new (
125120 bases : ArrayRef ,
126121 deltas : ArrayRef ,
127- validity : Validity ,
128122 offset : usize ,
129123 logical_len : usize ,
130124 ) -> VortexResult < Self > {
@@ -139,7 +133,7 @@ impl DeltaArray {
139133 deltas. len( )
140134 )
141135 }
142- if bases. dtype ( ) != deltas. dtype ( ) {
136+ if ! bases. dtype ( ) . eq_ignore_nullability ( deltas. dtype ( ) ) {
143137 vortex_bail ! (
144138 "DeltaArray: bases and deltas must have the same dtype, got {:?} and {:?}" ,
145139 bases. dtype( ) ,
@@ -157,16 +151,6 @@ impl DeltaArray {
157151 vortex_bail ! ( "DeltaArray: ptype must be an integer, got {}" , ptype) ;
158152 }
159153
160- if let Some ( vlen) = validity. maybe_len ( )
161- && vlen != logical_len
162- {
163- vortex_bail ! (
164- "DeltaArray: validity length ({}) must match logical_len ({})" ,
165- vlen,
166- logical_len
167- ) ;
168- }
169-
170154 let lanes = lane_count ( ptype) ;
171155
172156 if ( deltas. len ( ) % 1024 == 0 ) != ( bases. len ( ) % lanes == 0 ) {
@@ -179,23 +163,21 @@ impl DeltaArray {
179163 }
180164
181165 // SAFETY: validation done above
182- Ok ( unsafe { Self :: new_unchecked ( bases, deltas, validity , offset, logical_len) } )
166+ Ok ( unsafe { Self :: new_unchecked ( bases, deltas, offset, logical_len) } )
183167 }
184168
185169 pub ( crate ) unsafe fn new_unchecked (
186170 bases : ArrayRef ,
187171 deltas : ArrayRef ,
188- validity : Validity ,
189172 offset : usize ,
190173 logical_len : usize ,
191174 ) -> Self {
192175 Self {
193176 offset,
194177 len : logical_len,
195- dtype : bases. dtype ( ) . clone ( ) ,
178+ dtype : bases. dtype ( ) . with_nullability ( deltas . dtype ( ) . nullability ( ) ) ,
196179 bases,
197180 deltas,
198- validity,
199181 stats_set : Default :: default ( ) ,
200182 }
201183 }
@@ -236,9 +218,10 @@ pub(crate) fn lane_count(ptype: PType) -> usize {
236218 match_each_unsigned_integer_ptype ! ( ptype, |T | { T :: LANES } )
237219}
238220
239- impl ValidityHelper for DeltaArray {
240- fn validity ( & self ) -> & Validity {
241- & self . validity
221+ impl ValidityChildSliceHelper for DeltaArray {
222+ fn unsliced_child_and_slice ( & self ) -> ( & ArrayRef , usize , usize ) {
223+ let ( start, len) = ( self . offset ( ) , self . len ( ) ) ;
224+ ( self . deltas ( ) , start, start + len)
242225 }
243226}
244227
0 commit comments