@@ -221,6 +221,43 @@ mod tests {
221221 Ok ( ( ) )
222222 }
223223
224+ #[ test]
225+ fn test_filter_with_offset_nonuniform ( ) -> VortexResult < ( ) > {
226+ // Test filtering with offset > 0 using non-uniform base values.
227+ // This catches slice_chunks bugs where inner coordinates are miscalculated.
228+ let mut ctx = ExecutionCtx :: new ( LEGACY_SESSION . clone ( ) ) ;
229+
230+ // Use non-uniform values so that incorrect slicing is detectable.
231+ let base_values: Vec < u16 > = ( 0u16 ..4096 ) . collect ( ) ;
232+ let array = PrimitiveArray :: from_iter ( base_values) . into_array ( ) ;
233+
234+ // Patch at index 5 (value becomes 9999) and index 1030 (value becomes 8888).
235+ let patched_indices = buffer ! [ 5u16 , 1030 ] . into_array ( ) ;
236+ let patched_values = buffer ! [ 9999u16 , 8888 ] . into_array ( ) ;
237+
238+ let patches = Patches :: new ( 4096 , 0 , patched_indices, patched_values, None ) ?;
239+ let array = PatchedArray :: from_array_and_patches ( array, & patches, & mut ctx) ?. into_array ( ) ;
240+
241+ // Slice to create offset > 0.
242+ // After slice(5..4096), logical position 0 = original position 5 (patched to 9999).
243+ let sliced = array. slice ( 5 ..4096 ) ?. optimize ( ) ?;
244+ assert_eq ! ( sliced. len( ) , 4091 ) ;
245+
246+ // Filter that touches the first 2 chunks.
247+ // Logical indices: 0 (was 5, patched), 1 (was 6, value 6), 1025 (was 1030, patched).
248+ let mask = Mask :: from_indices ( 4091 , vec ! [ 0 , 1 , 1025 ] ) ;
249+ let filtered = sliced
250+ . filter ( mask) ?
251+ . optimize ( ) ?
252+ . execute :: < PrimitiveArray > ( & mut ctx) ?;
253+
254+ // Expected: 9999 (patched at logical 0), 6 (original at logical 1), 8888 (patched at logical 1025).
255+ let expected = PrimitiveArray :: from_iter ( [ 9999u16 , 6 , 8888 ] ) ;
256+ assert_arrays_eq ! ( expected, filtered) ;
257+
258+ Ok ( ( ) )
259+ }
260+
224261 #[ test]
225262 fn test_filter_with_offset_last_chunk ( ) -> VortexResult < ( ) > {
226263 // Test filtering with offset > 0 where the mask touches the last chunk.
0 commit comments