@@ -17,14 +17,15 @@ use vortex_array::Precision;
1717use vortex_array:: arrays:: BoolArray ;
1818use vortex_array:: buffer:: BufferHandle ;
1919use vortex_array:: dtype:: DType ;
20+ use vortex_array:: dtype:: Nullability ;
2021use vortex_array:: scalar:: Scalar ;
2122use vortex_array:: serde:: ArrayChildren ;
2223use vortex_array:: validity:: Validity ;
2324use vortex_array:: vtable;
2425use vortex_array:: vtable:: OperationsVTable ;
2526use vortex_array:: vtable:: VTable ;
26- use vortex_array:: vtable:: ValidityHelper ;
27- use vortex_array:: vtable:: ValidityVTableFromValidityHelper ;
27+ use vortex_array:: vtable:: ValidityVTable ;
28+ use vortex_array:: vtable:: child_to_validity ;
2829use vortex_array:: vtable:: validity_to_child;
2930use vortex_buffer:: BitBuffer ;
3031use vortex_buffer:: ByteBuffer ;
@@ -43,24 +44,25 @@ impl VTable for ByteBool {
4344 type ArrayData = ByteBoolData ;
4445
4546 type OperationsVTable = Self ;
46- type ValidityVTable = ValidityVTableFromValidityHelper ;
47+ type ValidityVTable = Self ;
4748
4849 fn id ( & self ) -> ArrayId {
4950 Self :: ID
5051 }
5152
5253 fn validate ( & self , data : & Self :: ArrayData , dtype : & DType , len : usize ) -> VortexResult < ( ) > {
53- ByteBoolData :: validate ( data. buffer ( ) , data. validity ( ) , dtype, len)
54+ let validity = data. validity ( ) ;
55+ ByteBoolData :: validate ( data. buffer ( ) , & validity, dtype, len)
5456 }
5557
5658 fn array_hash < H : std:: hash:: Hasher > ( array : & ByteBoolData , state : & mut H , precision : Precision ) {
5759 array. buffer . array_hash ( state, precision) ;
58- array. validity . array_hash ( state, precision) ;
60+ array. validity ( ) . array_hash ( state, precision) ;
5961 }
6062
6163 fn array_eq ( array : & ByteBoolData , other : & ByteBoolData , precision : Precision ) -> bool {
6264 array. buffer . array_eq ( & other. buffer , precision)
63- && array. validity . array_eq ( & other. validity , precision)
65+ && array. validity ( ) . array_eq ( & other. validity ( ) , precision)
6466 }
6567
6668 fn nbuffers ( _array : ArrayView < ' _ , Self > ) -> usize {
@@ -132,10 +134,6 @@ impl VTable for ByteBool {
132134 NUM_SLOTS ,
133135 slots. len( )
134136 ) ;
135- array. validity = match & slots[ VALIDITY_SLOT ] {
136- Some ( arr) => Validity :: Array ( arr. clone ( ) ) ,
137- None => Validity :: from ( array. validity . nullability ( ) ) ,
138- } ;
139137 array. slots = slots;
140138 Ok ( ( ) )
141139 }
@@ -150,7 +148,7 @@ impl VTable for ByteBool {
150148
151149 fn execute ( array : Array < Self > , _ctx : & mut ExecutionCtx ) -> VortexResult < ExecutionResult > {
152150 let boolean_buffer = BitBuffer :: from ( array. as_slice ( ) ) ;
153- let validity = array. validity ( ) . clone ( ) ;
151+ let validity = array. validity ( ) ? ;
154152 Ok ( ExecutionResult :: done (
155153 BoolArray :: new ( boolean_buffer, validity) . into_array ( ) ,
156154 ) )
@@ -174,7 +172,7 @@ pub(super) const SLOT_NAMES: [&str; NUM_SLOTS] = ["validity"];
174172#[ derive( Clone , Debug ) ]
175173pub struct ByteBoolData {
176174 buffer : BufferHandle ,
177- validity : Validity ,
175+ nullability : Nullability ,
178176 pub ( super ) slots : Vec < Option < ArrayRef > > ,
179177}
180178
@@ -194,15 +192,15 @@ impl ByteBool {
194192 /// Construct a [`ByteBoolArray`] from a `Vec<bool>` and validity.
195193 pub fn from_vec < V : Into < Validity > > ( data : Vec < bool > , validity : V ) -> ByteBoolArray {
196194 let data = ByteBoolData :: from_vec ( data, validity) ;
197- let dtype = DType :: Bool ( data. validity . nullability ( ) ) ;
195+ let dtype = DType :: Bool ( data. nullability ) ;
198196 let len = data. len ( ) ;
199197 unsafe { Array :: from_parts_unchecked ( ArrayParts :: new ( ByteBool , dtype, len, data) ) }
200198 }
201199
202200 /// Construct a [`ByteBoolArray`] from optional bools.
203201 pub fn from_option_vec ( data : Vec < Option < bool > > ) -> ByteBoolArray {
204202 let data = ByteBoolData :: from ( data) ;
205- let dtype = DType :: Bool ( data. validity . nullability ( ) ) ;
203+ let dtype = DType :: Bool ( data. nullability ) ;
206204 let len = data. len ( ) ;
207205 unsafe { Array :: from_parts_unchecked ( ArrayParts :: new ( ByteBool , dtype, len, data) ) }
208206 }
@@ -235,6 +233,10 @@ impl ByteBoolData {
235233 vec ! [ validity_to_child( validity, len) ]
236234 }
237235
236+ pub fn validity ( & self ) -> Validity {
237+ child_to_validity ( & self . slots [ VALIDITY_SLOT ] , self . nullability )
238+ }
239+
238240 pub fn new ( buffer : BufferHandle , validity : Validity ) -> Self {
239241 let length = buffer. len ( ) ;
240242 if let Some ( vlen) = validity. maybe_len ( )
@@ -249,7 +251,7 @@ impl ByteBoolData {
249251 let slots = Self :: make_slots ( & validity, length) ;
250252 Self {
251253 buffer,
252- validity,
254+ nullability : validity. nullability ( ) ,
253255 slots,
254256 }
255257 }
@@ -266,7 +268,7 @@ impl ByteBoolData {
266268
267269 /// Returns the validity mask for this array.
268270 pub fn validity_mask ( & self ) -> Mask {
269- self . validity . to_mask ( self . len ( ) )
271+ self . validity ( ) . to_mask ( self . len ( ) )
270272 }
271273
272274 // TODO(ngates): deprecate construction from vec
@@ -287,9 +289,9 @@ impl ByteBoolData {
287289 }
288290}
289291
290- impl ValidityHelper for ByteBoolData {
291- fn validity ( & self ) -> & Validity {
292- & self . validity
292+ impl ValidityVTable < ByteBool > for ByteBool {
293+ fn validity ( array : ArrayView < ' _ , ByteBool > ) -> VortexResult < Validity > {
294+ Ok ( array . data ( ) . validity ( ) )
293295 }
294296}
295297
0 commit comments