@@ -4,18 +4,18 @@ use std::sync::Arc;
4
4
use itertools:: Itertools ;
5
5
use vortex_dtype:: { DType , Nullability , StructDType } ;
6
6
use vortex_error:: { VortexExpect , VortexResult , vortex_bail} ;
7
+ use vortex_mask:: Mask ;
7
8
use vortex_scalar:: StructScalar ;
8
9
9
10
use crate :: arrays:: StructArray ;
10
- use crate :: builders:: { ArrayBuilder , ArrayBuilderExt , BoolBuilder , builder_with_capacity } ;
11
- use crate :: validity :: Validity ;
11
+ use crate :: builders:: lazy_validity_builder :: LazyNullBufferBuilder ;
12
+ use crate :: builders :: { ArrayBuilder , ArrayBuilderExt , builder_with_capacity } ;
12
13
use crate :: variants:: StructArrayTrait ;
13
14
use crate :: { Array , ArrayRef , Canonical } ;
14
15
15
16
pub struct StructBuilder {
16
17
builders : Vec < Box < dyn ArrayBuilder > > ,
17
- // TODO(ngates): this should be a NullBufferBuilder? Or mask builder?
18
- validity : BoolBuilder ,
18
+ validity : LazyNullBufferBuilder ,
19
19
struct_dtype : Arc < StructDType > ,
20
20
nullability : Nullability ,
21
21
dtype : DType ,
@@ -34,7 +34,7 @@ impl StructBuilder {
34
34
35
35
Self {
36
36
builders,
37
- validity : BoolBuilder :: with_capacity ( Nullability :: NonNullable , capacity) ,
37
+ validity : LazyNullBufferBuilder :: new ( capacity) ,
38
38
struct_dtype : struct_dtype. clone ( ) ,
39
39
nullability,
40
40
dtype : DType :: Struct ( struct_dtype, nullability) ,
@@ -54,7 +54,7 @@ impl StructBuilder {
54
54
for ( builder, field) in self . builders . iter_mut ( ) . zip_eq ( fields) {
55
55
builder. append_scalar ( & field) ?;
56
56
}
57
- self . validity . append_value ( true ) ;
57
+ self . validity . append_non_null ( ) ;
58
58
} else {
59
59
self . append_null ( )
60
60
}
@@ -84,7 +84,7 @@ impl ArrayBuilder for StructBuilder {
84
84
self . builders
85
85
. iter_mut ( )
86
86
. for_each ( |builder| builder. append_zeros ( n) ) ;
87
- self . validity . append_values ( true , n) ;
87
+ self . validity . append_n_non_nulls ( n) ;
88
88
}
89
89
90
90
fn append_nulls ( & mut self , n : usize ) {
@@ -93,7 +93,7 @@ impl ArrayBuilder for StructBuilder {
93
93
// We push zero values into our children when appending a null in case the children are
94
94
// themselves non-nullable.
95
95
. for_each ( |builder| builder. append_zeros ( n) ) ;
96
- self . validity . append_value ( false ) ;
96
+ self . validity . append_null ( ) ;
97
97
}
98
98
99
99
fn extend_from_array ( & mut self , array : & dyn Array ) -> VortexResult < ( ) > {
@@ -120,21 +120,15 @@ impl ArrayBuilder for StructBuilder {
120
120
a. append_to_builder ( builder. as_mut ( ) ) ?;
121
121
}
122
122
123
- match array. validity ( ) {
124
- Validity :: NonNullable | Validity :: AllValid => {
125
- self . validity . append_values ( true , array. len ( ) ) ;
126
- }
127
- Validity :: AllInvalid => {
128
- self . validity . append_values ( false , array. len ( ) ) ;
129
- }
130
- Validity :: Array ( validity) => {
131
- validity. append_to_builder ( & mut self . validity ) ?;
132
- }
133
- }
134
-
123
+ self . validity . append_validity_mask ( array. validity_mask ( ) ?) ;
135
124
Ok ( ( ) )
136
125
}
137
126
127
+ fn set_validity ( & mut self , validity : Mask ) {
128
+ self . validity = LazyNullBufferBuilder :: new ( validity. len ( ) ) ;
129
+ self . validity . append_validity_mask ( validity) ;
130
+ }
131
+
138
132
fn finish ( & mut self ) -> ArrayRef {
139
133
let len = self . len ( ) ;
140
134
let fields = self
@@ -156,10 +150,7 @@ impl ArrayBuilder for StructBuilder {
156
150
}
157
151
}
158
152
159
- let validity = match self . nullability {
160
- Nullability :: NonNullable => Validity :: NonNullable ,
161
- Nullability :: Nullable => Validity :: Array ( self . validity . finish ( ) ) ,
162
- } ;
153
+ let validity = self . validity . finish_with_nullability ( self . nullability ) ;
163
154
164
155
StructArray :: try_new ( self . struct_dtype . names ( ) . clone ( ) , fields, len, validity)
165
156
. vortex_expect ( "Fields must all have same length." )
0 commit comments