@@ -26,8 +26,7 @@ use crate::error::{_internal_datafusion_err, _internal_err};
2626use crate :: { arrow_datafusion_err, DataFusionError , Result , ScalarValue } ;
2727use arrow:: array:: { ArrayRef , PrimitiveArray } ;
2828use arrow:: buffer:: OffsetBuffer ;
29- use arrow:: compute;
30- use arrow:: compute:: { partition, SortColumn , SortOptions } ;
29+ use arrow:: compute:: { partition, take_arrays, SortColumn , SortOptions } ;
3130use arrow:: datatypes:: { Field , SchemaRef , UInt32Type } ;
3231use arrow:: record_batch:: RecordBatch ;
3332use arrow_array:: cast:: AsArray ;
@@ -98,7 +97,7 @@ pub fn get_record_batch_at_indices(
9897 record_batch : & RecordBatch ,
9998 indices : & PrimitiveArray < UInt32Type > ,
10099) -> Result < RecordBatch > {
101- let new_columns = take_arrays ( record_batch. columns ( ) , indices) ?;
100+ let new_columns = take_arrays ( record_batch. columns ( ) , indices, None ) ?;
102101 RecordBatch :: try_new_with_options (
103102 record_batch. schema ( ) ,
104103 new_columns,
@@ -290,24 +289,6 @@ pub(crate) fn parse_identifiers(s: &str) -> Result<Vec<Ident>> {
290289 Ok ( idents)
291290}
292291
293- /// Construct a new [`Vec`] of [`ArrayRef`] from the rows of the `arrays` at the `indices`.
294- ///
295- /// TODO: use implementation in arrow-rs when available:
296- /// <https://github.com/apache/arrow-rs/pull/6475>
297- pub fn take_arrays ( arrays : & [ ArrayRef ] , indices : & dyn Array ) -> Result < Vec < ArrayRef > > {
298- arrays
299- . iter ( )
300- . map ( |array| {
301- compute:: take (
302- array. as_ref ( ) ,
303- indices,
304- None , // None: no index check
305- )
306- . map_err ( |e| arrow_datafusion_err ! ( e) )
307- } )
308- . collect ( )
309- }
310-
311292pub ( crate ) fn parse_identifiers_normalized ( s : & str , ignore_case : bool ) -> Vec < String > {
312293 parse_identifiers ( s)
313294 . unwrap_or_default ( )
@@ -1003,40 +984,6 @@ mod tests {
1003984 Ok ( ( ) )
1004985 }
1005986
1006- #[ test]
1007- fn test_take_arrays ( ) -> Result < ( ) > {
1008- let arrays: Vec < ArrayRef > = vec ! [
1009- Arc :: new( Float64Array :: from( vec![ 5.0 , 7.0 , 8.0 , 9. , 10. ] ) ) ,
1010- Arc :: new( Float64Array :: from( vec![ 2.0 , 3.0 , 3.0 , 4.0 , 5.0 ] ) ) ,
1011- Arc :: new( Float64Array :: from( vec![ 5.0 , 7.0 , 8.0 , 10. , 11.0 ] ) ) ,
1012- Arc :: new( Float64Array :: from( vec![ 15.0 , 13.0 , 8.0 , 5. , 0.0 ] ) ) ,
1013- ] ;
1014-
1015- let row_indices_vec: Vec < Vec < u32 > > = vec ! [
1016- // Get rows 0 and 1
1017- vec![ 0 , 1 ] ,
1018- // Get rows 0 and 1
1019- vec![ 0 , 2 ] ,
1020- // Get rows 1 and 3
1021- vec![ 1 , 3 ] ,
1022- // Get rows 2 and 4
1023- vec![ 2 , 4 ] ,
1024- ] ;
1025- for row_indices in row_indices_vec {
1026- let indices: PrimitiveArray < UInt32Type > =
1027- PrimitiveArray :: from_iter_values ( row_indices. iter ( ) . cloned ( ) ) ;
1028- let chunk = take_arrays ( & arrays, & indices) ?;
1029- for ( arr_orig, arr_chunk) in arrays. iter ( ) . zip ( & chunk) {
1030- for ( idx, orig_idx) in row_indices. iter ( ) . enumerate ( ) {
1031- let res1 = ScalarValue :: try_from_array ( arr_orig, * orig_idx as usize ) ?;
1032- let res2 = ScalarValue :: try_from_array ( arr_chunk, idx) ?;
1033- assert_eq ! ( res1, res2) ;
1034- }
1035- }
1036- }
1037- Ok ( ( ) )
1038- }
1039-
1040987 #[ test]
1041988 fn test_get_at_indices ( ) -> Result < ( ) > {
1042989 let in_vec = vec ! [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ;
0 commit comments