@@ -254,7 +254,12 @@ fn take_impl<IndexType: ArrowPrimitiveType>(
254
254
} )
255
255
. collect( ) ;
256
256
257
- Ok ( Arc :: new( StructArray :: from( ( fields, is_valid) ) ) as ArrayRef )
257
+ if fields. is_empty( ) {
258
+ let nulls = NullBuffer :: new( BooleanBuffer :: new( is_valid, 0 , indices. len( ) ) ) ;
259
+ Ok ( Arc :: new( StructArray :: new_empty_fields( indices. len( ) , Some ( nulls) ) ) )
260
+ } else {
261
+ Ok ( Arc :: new( StructArray :: from( ( fields, is_valid) ) ) as ArrayRef )
262
+ }
258
263
}
259
264
DataType :: Dictionary ( _, _) => downcast_dictionary_array! {
260
265
values => Ok ( Arc :: new( take_dict( values, indices) ?) ) ,
@@ -1968,6 +1973,15 @@ mod tests {
1968
1973
] ) ;
1969
1974
1970
1975
assert_eq ! ( & expected, actual) ;
1976
+
1977
+ let nulls = NullBuffer :: from ( & [ false , true , false , true , false , true ] ) ;
1978
+ let empty_struct_arr = StructArray :: new_empty_fields ( 6 , Some ( nulls) ) ;
1979
+ let index = UInt32Array :: from ( vec ! [ 0 , 2 , 1 , 4 ] ) ;
1980
+ let actual = take ( & empty_struct_arr, & index, None ) . unwrap ( ) ;
1981
+
1982
+ let expected_nulls = NullBuffer :: from ( & [ false , false , true , false ] ) ;
1983
+ let expected_struct_arr = StructArray :: new_empty_fields ( 4 , Some ( expected_nulls) ) ;
1984
+ assert_eq ! ( & expected_struct_arr, actual. as_struct( ) ) ;
1971
1985
}
1972
1986
1973
1987
#[ test]
0 commit comments