@@ -94,11 +94,8 @@ use crate::{StructVector, Vector, VectorMut, VectorMutOps, VectorOps};
9494/// ```
9595#[ derive( Debug , Clone ) ]
9696pub struct StructVectorMut {
97- /// The fields of the `StructVectorMut`, each stored column-wise as a [`VectorMut`].
98- ///
99- /// We store this as a mutable vector instead of a fixed-sized type since vectors do not have an
100- /// associated [`DType`](vortex_dtype::DType), thus users can add field columns if they need.
101- pub ( super ) fields : Vec < VectorMut > ,
97+ /// The (owned) fields of the `StructVectorMut`, each stored column-wise as a [`VectorMut`].
98+ pub ( super ) fields : Box < [ VectorMut ] > ,
10299
103100 /// The validity mask (where `true` represents an element is **not** null).
104101 pub ( super ) validity : MaskMut ,
@@ -119,7 +116,7 @@ impl StructVectorMut {
119116 ///
120117 /// - Any field vector has a length that does not match the length of other fields.
121118 /// - The validity mask length does not match the field length.
122- pub fn new ( fields : Vec < VectorMut > , validity : MaskMut ) -> Self {
119+ pub fn new ( fields : Box < [ VectorMut ] > , validity : MaskMut ) -> Self {
123120 Self :: try_new ( fields, validity) . vortex_expect ( "Failed to create `StructVectorMut`" )
124121 }
125122
@@ -131,7 +128,7 @@ impl StructVectorMut {
131128 ///
132129 /// - Any field vector has a length that does not match the length of other fields.
133130 /// - The validity mask length does not match the field length.
134- pub fn try_new ( fields : Vec < VectorMut > , validity : MaskMut ) -> VortexResult < Self > {
131+ pub fn try_new ( fields : Box < [ VectorMut ] > , validity : MaskMut ) -> VortexResult < Self > {
135132 let len = if fields. is_empty ( ) {
136133 validity. len ( )
137134 } else {
@@ -173,7 +170,7 @@ impl StructVectorMut {
173170 ///
174171 /// - All field vectors have the same length.
175172 /// - The validity mask has a length equal to the field length.
176- pub unsafe fn new_unchecked ( fields : Vec < VectorMut > , validity : MaskMut ) -> Self {
173+ pub unsafe fn new_unchecked ( fields : Box < [ VectorMut ] > , validity : MaskMut ) -> Self {
177174 let len = if fields. is_empty ( ) {
178175 validity. len ( )
179176 } else {
@@ -192,13 +189,13 @@ impl StructVectorMut {
192189 }
193190
194191 /// Decomposes the struct vector into its constituent parts (fields, validity, and length).
195- pub fn into_parts ( self ) -> ( Vec < VectorMut > , MaskMut , usize ) {
192+ pub fn into_parts ( self ) -> ( Box < [ VectorMut ] > , MaskMut , usize ) {
196193 ( self . fields , self . validity , self . len )
197194 }
198195
199196 /// Returns the fields of the `StructVectorMut`, each stored column-wise as a [`VectorMut`].
200197 pub fn fields ( & self ) -> & [ VectorMut ] {
201- self . fields . as_slice ( )
198+ self . fields . as_ref ( )
202199 }
203200
204201 /// Finds the minimum capacity of all field vectors.
@@ -317,7 +314,7 @@ impl VectorMutOps for StructVectorMut {
317314 self . len = at;
318315
319316 Self {
320- fields : split_fields,
317+ fields : split_fields. into_boxed_slice ( ) ,
321318 len : split_len,
322319 validity : split_validity,
323320 }
@@ -362,7 +359,7 @@ mod tests {
362359
363360 #[ test]
364361 fn test_empty_fields ( ) {
365- let mut struct_vec = StructVectorMut :: try_new ( vec ! [ ] , MaskMut :: new_true ( 10 ) ) . unwrap ( ) ;
362+ let mut struct_vec = StructVectorMut :: try_new ( Box :: new ( [ ] ) , MaskMut :: new_true ( 10 ) ) . unwrap ( ) ;
366363 let second_half = struct_vec. split_off ( 6 ) ;
367364 assert_eq ! ( struct_vec. len( ) , 6 ) ;
368365 assert_eq ! ( second_half. len( ) , 4 ) ;
@@ -430,12 +427,12 @@ mod tests {
430427 #[ test]
431428 fn test_split_unsplit_values ( ) {
432429 let mut struct_vec = StructVectorMut :: try_new (
433- vec ! [
434- NullVector :: new( 8 ) . try_into_mut ( ) . unwrap ( ) . into( ) ,
430+ Box :: new ( [
431+ NullVectorMut :: new ( 8 ) . into ( ) ,
435432 BoolVectorMut :: from_iter ( [ true , false , true , false , true , false , true , false ] )
436433 . into ( ) ,
437434 PVectorMut :: < i32 > :: from_iter ( [ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 ] ) . into ( ) ,
438- ] ,
435+ ] ) ,
439436 MaskMut :: new_true ( 8 ) ,
440437 )
441438 . unwrap ( ) ;
@@ -471,11 +468,11 @@ mod tests {
471468 #[ test]
472469 fn test_extend_and_append_nulls ( ) {
473470 let mut struct_vec = StructVectorMut :: try_new (
474- vec ! [
471+ Box :: new ( [
475472 NullVector :: new ( 3 ) . try_into_mut ( ) . unwrap ( ) . into ( ) ,
476473 BoolVectorMut :: from_iter ( [ true , false , true ] ) . into ( ) ,
477474 PVectorMut :: < i32 > :: from_iter ( [ 10 , 20 , 30 ] ) . into ( ) ,
478- ] ,
475+ ] ) ,
479476 MaskMut :: new_true ( 3 ) ,
480477 )
481478 . unwrap ( ) ;
@@ -523,11 +520,11 @@ mod tests {
523520 let original_int = vec ! [ Some ( 100i32 ) , None , Some ( 200 ) , Some ( 300 ) ] ;
524521
525522 let struct_vec = StructVectorMut :: try_new (
526- vec ! [
523+ Box :: new ( [
527524 NullVector :: new ( 4 ) . try_into_mut ( ) . unwrap ( ) . into ( ) ,
528525 BoolVectorMut :: from_iter ( original_bool. clone ( ) ) . into ( ) ,
529526 PVectorMut :: < i32 > :: from_iter ( original_int. clone ( ) ) . into ( ) ,
530- ] ,
527+ ] ) ,
531528 MaskMut :: new_true ( 4 ) ,
532529 )
533530 . unwrap ( ) ;
@@ -547,24 +544,24 @@ mod tests {
547544 #[ test]
548545 fn test_nested_struct ( ) {
549546 let inner1 = StructVectorMut :: try_new (
550- vec ! [
547+ Box :: new ( [
551548 NullVector :: new ( 4 ) . try_into_mut ( ) . unwrap ( ) . into ( ) ,
552549 BoolVectorMut :: from_iter ( [ true , false , true , false ] ) . into ( ) ,
553- ] ,
550+ ] ) ,
554551 MaskMut :: new_true ( 4 ) ,
555552 )
556553 . unwrap ( )
557554 . into ( ) ;
558555
559556 let inner2 = StructVectorMut :: try_new (
560- vec ! [ PVectorMut :: <u32 >:: from_iter( [ 100 , 200 , 300 , 400 ] ) . into( ) ] ,
557+ Box :: new ( [ PVectorMut :: < u32 > :: from_iter ( [ 100 , 200 , 300 , 400 ] ) . into ( ) ] ) ,
561558 MaskMut :: new_true ( 4 ) ,
562559 )
563560 . unwrap ( )
564561 . into ( ) ;
565562
566563 let mut outer =
567- StructVectorMut :: try_new ( vec ! [ inner1, inner2] , MaskMut :: new_true ( 4 ) ) . unwrap ( ) ;
564+ StructVectorMut :: try_new ( Box :: new ( [ inner1, inner2] ) , MaskMut :: new_true ( 4 ) ) . unwrap ( ) ;
568565
569566 let second = outer. split_off ( 2 ) ;
570567 assert_eq ! ( outer. len( ) , 2 ) ;
@@ -579,11 +576,11 @@ mod tests {
579576 fn test_reserve ( ) {
580577 // Test that reserve increases capacity for all fields correctly.
581578 let mut struct_vec = StructVectorMut :: try_new (
582- vec ! [
579+ Box :: new ( [
583580 NullVectorMut :: new ( 3 ) . into ( ) ,
584581 BoolVectorMut :: from_iter ( [ true , false , true ] ) . into ( ) ,
585582 PVectorMut :: < i32 > :: from_iter ( [ 10 , 20 , 30 ] ) . into ( ) ,
586- ] ,
583+ ] ) ,
587584 MaskMut :: new_true ( 3 ) ,
588585 )
589586 . unwrap ( ) ;
@@ -606,10 +603,10 @@ mod tests {
606603
607604 // Test reserve on an empty struct.
608605 let mut empty_struct = StructVectorMut :: try_new (
609- vec ! [
606+ Box :: new ( [
610607 NullVectorMut :: new ( 0 ) . into ( ) ,
611608 BoolVectorMut :: with_capacity ( 0 ) . into ( ) ,
612- ] ,
609+ ] ) ,
613610 MaskMut :: new_true ( 0 ) ,
614611 )
615612 . unwrap ( ) ;
@@ -621,11 +618,11 @@ mod tests {
621618 #[ test]
622619 fn test_freeze_and_new_unchecked ( ) {
623620 // Test new_unchecked creates a valid struct, and freeze preserves data correctly.
624- let fields = vec ! [
621+ let fields = Box :: new ( [
625622 NullVectorMut :: new ( 4 ) . into ( ) ,
626623 BoolVectorMut :: from_iter ( [ Some ( true ) , None , Some ( false ) , Some ( true ) ] ) . into ( ) ,
627624 PVectorMut :: < i32 > :: from_iter ( [ Some ( 100 ) , Some ( 200 ) , None , Some ( 400 ) ] ) . into ( ) ,
628- ] ;
625+ ] ) ;
629626
630627 let validity = Mask :: from_iter ( [ true , false , true , true ] )
631628 . try_into_mut ( )
0 commit comments