@@ -181,7 +181,9 @@ impl VTable for ALP {
181181 . map ( |dtype| children. get ( 3 , & dtype, usize:: try_from ( p. chunk_offsets_len ( ) ) ?) )
182182 . transpose ( ) ?;
183183
184- Patches :: new ( len, p. offset ( ) ?, indices, values, chunk_offsets)
184+ // The indices child already has the offset embedded (via Binary(Sub) expression),
185+ // so we pass offset 0 to avoid double-wrapping.
186+ Patches :: new ( len, 0 , indices, values, chunk_offsets)
185187 } )
186188 . transpose ( ) ?;
187189
@@ -200,10 +202,10 @@ impl VTable for ALP {
200202 let patches_info = array
201203 . patches
202204 . as_ref ( )
203- . map ( |p| ( p. array_len ( ) , p. offset ( ) , p . chunk_offsets ( ) . is_some ( ) ) ) ;
205+ . map ( |p| ( p. array_len ( ) , p. chunk_offsets ( ) . is_some ( ) ) ) ;
204206
205207 let expected_children = match & patches_info {
206- Some ( ( _, _ , has_chunk_offsets) ) => 1 + 2 + if * has_chunk_offsets { 1 } else { 0 } ,
208+ Some ( ( _, has_chunk_offsets) ) => 1 + 2 + if * has_chunk_offsets { 1 } else { 0 } ,
207209 None => 1 ,
208210 } ;
209211
@@ -219,7 +221,7 @@ impl VTable for ALP {
219221 . next ( )
220222 . ok_or_else ( || vortex_err ! ( "Expected encoded child" ) ) ?;
221223
222- if let Some ( ( array_len, offset , _has_chunk_offsets) ) = patches_info {
224+ if let Some ( ( array_len, _has_chunk_offsets) ) = patches_info {
223225 let indices = children_iter
224226 . next ( )
225227 . ok_or_else ( || vortex_err ! ( "Expected patch indices child" ) ) ?;
@@ -228,13 +230,9 @@ impl VTable for ALP {
228230 . ok_or_else ( || vortex_err ! ( "Expected patch values child" ) ) ?;
229231 let chunk_offsets = children_iter. next ( ) ;
230232
231- array. patches = Some ( Patches :: new (
232- array_len,
233- offset,
234- indices,
235- values,
236- chunk_offsets,
237- ) ?) ;
233+ // The indices child already has the offset embedded (via Binary(Sub) expression),
234+ // so we pass offset 0 to avoid double-wrapping.
235+ array. patches = Some ( Patches :: new ( array_len, 0 , indices, values, chunk_offsets) ?) ;
238236 }
239237
240238 Ok ( ( ) )
@@ -799,10 +797,11 @@ mod tests {
799797 ) ;
800798
801799 // Rebuild the patches WITHOUT chunk_offsets to simulate deserialized patches.
800+ let ( raw_indices, offset) = original_patches. raw_indices_and_offset ( ) ;
802801 let patches_without_chunk_offsets = Patches :: new (
803802 original_patches. array_len ( ) ,
804- original_patches . offset ( ) ,
805- original_patches . indices ( ) . clone ( ) ,
803+ offset,
804+ raw_indices . clone ( ) ,
806805 original_patches. values ( ) . clone ( ) ,
807806 None , // NO chunk_offsets - this triggers the bug!
808807 )
0 commit comments