11// SPDX-License-Identifier: Apache-2.0
22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
4+ use vortex_array:: ArrayRef ;
45use vortex_array:: DeserializeMetadata ;
56use vortex_array:: ProstMetadata ;
67use vortex_array:: SerializeMetadata ;
@@ -24,6 +25,7 @@ use vortex_dtype::PType;
2425use vortex_error:: VortexError ;
2526use vortex_error:: VortexResult ;
2627use vortex_error:: vortex_bail;
28+ use vortex_error:: vortex_ensure;
2729use vortex_error:: vortex_err;
2830use vortex_vector:: VectorMutOps ;
2931
@@ -70,6 +72,75 @@ impl VTable for BitPackedVTable {
7072 BitPackedVTable . as_vtable ( )
7173 }
7274
75+ fn with_children ( array : & mut Self :: Array , children : Vec < ArrayRef > ) -> VortexResult < ( ) > {
76+ // Children: patches (if present): indices, values, chunk_offsets; then validity (if present)
77+ let patches_info = array
78+ . patches ( )
79+ . map ( |p| ( p. offset ( ) , p. chunk_offsets ( ) . is_some ( ) ) ) ;
80+
81+ let mut child_idx = 0 ;
82+ let patches = if let Some ( ( patch_offset, has_chunk_offsets) ) = patches_info {
83+ let patch_indices = children
84+ . get ( child_idx)
85+ . ok_or_else ( || vortex_err ! ( "Expected patch_indices child at index {}" , child_idx) ) ?
86+ . clone ( ) ;
87+ child_idx += 1 ;
88+
89+ let patch_values = children
90+ . get ( child_idx)
91+ . ok_or_else ( || vortex_err ! ( "Expected patch_values child at index {}" , child_idx) ) ?
92+ . clone ( ) ;
93+ child_idx += 1 ;
94+
95+ let patch_chunk_offsets = if has_chunk_offsets {
96+ let offsets = children
97+ . get ( child_idx)
98+ . ok_or_else ( || {
99+ vortex_err ! ( "Expected patch_chunk_offsets child at index {}" , child_idx)
100+ } ) ?
101+ . clone ( ) ;
102+ child_idx += 1 ;
103+ Some ( offsets)
104+ } else {
105+ None
106+ } ;
107+
108+ Some ( Patches :: new (
109+ array. len ( ) ,
110+ patch_offset,
111+ patch_indices,
112+ patch_values,
113+ patch_chunk_offsets,
114+ ) )
115+ } else {
116+ None
117+ } ;
118+
119+ let validity = if child_idx < children. len ( ) {
120+ Validity :: Array ( children[ child_idx] . clone ( ) )
121+ } else {
122+ Validity :: from ( array. dtype ( ) . nullability ( ) )
123+ } ;
124+
125+ let expected_children = child_idx
126+ + if matches ! ( validity, Validity :: Array ( _) ) {
127+ 1
128+ } else {
129+ 0
130+ } ;
131+ vortex_ensure ! (
132+ children. len( ) == expected_children,
133+ "Expected {} children, got {}" ,
134+ expected_children,
135+ children. len( )
136+ ) ;
137+
138+ array. patches = patches;
139+ array. validity = validity;
140+
141+ Ok ( ( ) )
142+ }
143+
73144 fn metadata ( array : & BitPackedArray ) -> VortexResult < Self :: Metadata > {
74145 Ok ( ProstMetadata ( BitPackedMetadata {
75146 bit_width : array. bit_width ( ) as u32 ,
0 commit comments