@@ -364,7 +364,7 @@ where
364364 run_arrays
365365 . iter ( )
366366 . scan ( R :: default_value ( ) , |acc, run_array| {
367- * acc = * acc + * run_array. run_ends ( ) . values ( ) . last ( ) . unwrap ( ) ;
367+ * acc = * acc + R :: Native :: from_usize ( run_array. len ( ) ) . unwrap ( ) ;
368368 Some ( * acc)
369369 } ) ,
370370 )
@@ -379,18 +379,17 @@ where
379379 let adjustment = needed_run_end_adjustments[ i] ;
380380 run_array
381381 . run_ends ( )
382- . values ( )
383- . iter ( )
384- . map ( move |run_end| * run_end + adjustment)
382+ . sliced_values ( )
383+ . map ( move |run_end| run_end + adjustment)
385384 } ,
386385 ) ) ;
387386
388- let all_values = concat (
389- & run_arrays
390- . iter ( )
391- . map ( |x| x . values ( ) . as_ref ( ) )
392- . collect :: < Vec < _ > > ( ) ,
393- ) ?;
387+ let values_slices : Vec < ArrayRef > = run_arrays
388+ . iter ( )
389+ . map ( |run_array| run_array . values_slice ( ) )
390+ . collect ( ) ;
391+
392+ let all_values = concat ( & values_slices . iter ( ) . map ( |x| x . as_ref ( ) ) . collect :: < Vec < _ > > ( ) ) ?;
394393
395394 let builder = ArrayDataBuilder :: new ( run_arrays[ 0 ] . data_type ( ) . clone ( ) )
396395 . len ( total_len)
@@ -1716,9 +1715,6 @@ mod tests {
17161715 }
17171716
17181717 #[ test]
1719- #[ should_panic = "assertion `left == right` failed\n left: [20, 20, 40, 40, 40]\n right: [10, 10, 20, 20, 30, 40, 40, 40]" ]
1720- // TODO: fix concat of RunArrays to account for sliced RunArray's
1721- // https://github.com/apache/arrow-rs/issues/9018
17221718 fn test_concat_sliced_run_array ( ) {
17231719 // Slicing away first run in both arrays
17241720 let run_ends1 = Int32Array :: from ( vec ! [ 2 , 4 ] ) ;
@@ -1879,4 +1875,29 @@ mod tests {
18791875 assert_eq ! ( values. len( ) , 6 ) ;
18801876 assert_eq ! ( & [ 10 , 20 , 30 , 40 , 50 , 60 ] , values. values( ) ) ;
18811877 }
1878+
1879+ #[ test]
1880+ fn test_concat_run_array_with_truncated_run ( ) {
1881+ // Create a run array with run ends [2, 5] and values [10, 20]
1882+ // Logical: [10, 10, 20, 20, 20]
1883+ let run_ends1 = Int32Array :: from ( vec ! [ 2 , 5 ] ) ;
1884+ let values1 = Int32Array :: from ( vec ! [ 10 , 20 ] ) ;
1885+ let array1 = RunArray :: try_new ( & run_ends1, & values1) . unwrap ( ) ;
1886+ let array1_sliced = array1. slice ( 0 , 3 ) ;
1887+
1888+ let run_ends2 = Int32Array :: from ( vec ! [ 2 ] ) ;
1889+ let values2 = Int32Array :: from ( vec ! [ 30 ] ) ;
1890+ let array2 = RunArray :: try_new ( & run_ends2, & values2) . unwrap ( ) ;
1891+
1892+ let result = concat ( & [ & array1_sliced, & array2] ) . unwrap ( ) ;
1893+ let result_run_array = result. as_run :: < Int32Type > ( ) ;
1894+
1895+ // Result should be [10, 10, 20, 30, 30]
1896+ // Run ends should be [2, 3, 5]
1897+ assert_eq ! ( result_run_array. len( ) , 5 ) ;
1898+ let run_ends = result_run_array. run_ends ( ) . values ( ) ;
1899+ let values = result_run_array. values ( ) . as_primitive :: < Int32Type > ( ) ;
1900+ assert_eq ! ( values. values( ) , & [ 10 , 20 , 30 ] ) ;
1901+ assert_eq ! ( & [ 2 , 3 , 5 ] , run_ends) ;
1902+ }
18821903}
0 commit comments