@@ -670,12 +670,15 @@ impl Patches {
670670 let offset_within_chunk = chunk_offsets
671671 . as_ref ( )
672672 . map ( |chunk_offsets| -> VortexResult < usize > {
673- let base_offset = chunk_offsets
673+ let absolute_chunk_base = chunk_offsets
674674 . scalar_at ( 0 ) ?
675675 . as_primitive ( )
676676 . as_ :: < usize > ( )
677677 . ok_or_else ( || vortex_err ! ( "chunk offset does not fit in usize" ) ) ?;
678- Ok ( slice_start_idx - base_offset)
678+ let absolute_slice_start = self . chunk_offset_at ( 0 ) ?
679+ + self . offset_within_chunk . unwrap_or ( 0 )
680+ + slice_start_idx;
681+ Ok ( absolute_slice_start - absolute_chunk_base)
679682 } )
680683 . transpose ( ) ?;
681684
@@ -2151,6 +2154,20 @@ mod test {
21512154 ) ;
21522155 }
21532156
2157+ #[ test]
2158+ fn test_nested_slice_with_dropped_first_chunk ( ) {
2159+ // PATCH_CHUNK_SIZE = 1024, so the two patches land in different chunks.
2160+ let indices = buffer ! [ 0u64 , 1024 ] . into_array ( ) ;
2161+ let values = buffer ! [ 1i32 , 2 ] . into_array ( ) ;
2162+ let chunk_offsets = buffer ! [ 0u64 , 1 ] . into_array ( ) ;
2163+ let patches = Patches :: new ( 2048 , 0 , indices, values, Some ( chunk_offsets) ) . unwrap ( ) ;
2164+
2165+ // Drop chunk 0, then re-slice the result.
2166+ let dropped_first = patches. slice ( 1024 ..2048 ) . unwrap ( ) . unwrap ( ) ;
2167+ let resliced = dropped_first. slice ( 0 ..1024 ) . unwrap ( ) . unwrap ( ) ;
2168+ assert_eq ! ( resliced. num_patches( ) , 1 ) ;
2169+ }
2170+
21542171 #[ test]
21552172 fn test_index_larger_than_length ( ) {
21562173 let chunk_offsets = buffer ! [ 0u64 ] . into_array ( ) ;
0 commit comments