@@ -37,7 +37,7 @@ use arrow_array::*;
37
37
use arrow_buffer:: { ArrowNativeType , BooleanBufferBuilder , NullBuffer , OffsetBuffer } ;
38
38
use arrow_data:: transform:: { Capacities , MutableArrayData } ;
39
39
use arrow_schema:: { ArrowError , DataType , FieldRef , SchemaRef } ;
40
- use std:: sync:: Arc ;
40
+ use std:: { collections :: HashSet , sync:: Arc } ;
41
41
42
42
fn binary_capacity < T : ByteArrayType > ( arrays : & [ & dyn Array ] ) -> Capacities {
43
43
let mut item_capacity = 0 ;
@@ -223,8 +223,22 @@ pub fn concat(arrays: &[&dyn Array]) -> Result<ArrayRef, ArrowError> {
223
223
224
224
let d = arrays[ 0 ] . data_type ( ) ;
225
225
if arrays. iter ( ) . skip ( 1 ) . any ( |array| array. data_type ( ) != d) {
226
+ // Get all the unique data types
227
+ let input_data_types = {
228
+ let unique = arrays
229
+ . iter ( )
230
+ . map ( |array| array. data_type ( ) )
231
+ . collect :: < HashSet < & DataType > > ( ) ;
232
+
233
+ unique
234
+ . iter ( )
235
+ . map ( |dt| format ! ( "{dt}" ) )
236
+ . collect :: < Vec < _ > > ( )
237
+ . join ( ", " )
238
+ } ;
239
+
226
240
return Err ( ArrowError :: InvalidArgumentError (
227
- "It is not possible to concatenate arrays of different data types." . to_string ( ) ,
241
+ format ! ( "It is not possible to concatenate arrays of different data types ({input_data_types})." ) ,
228
242
) ) ;
229
243
}
230
244
@@ -342,7 +356,13 @@ mod tests {
342
356
& PrimitiveArray :: < Int64Type > :: from ( vec ! [ Some ( -1 ) , Some ( 2 ) , None ] ) ,
343
357
& StringArray :: from ( vec ! [ Some ( "hello" ) , Some ( "bar" ) , Some ( "world" ) ] ) ,
344
358
] ) ;
345
- assert ! ( re. is_err( ) ) ;
359
+
360
+ match re. expect_err ( "concat should have failed" ) {
361
+ ArrowError :: InvalidArgumentError ( desc) => {
362
+ assert_eq ! ( desc, "It is not possible to concatenate arrays of different data types (Int64, Utf8)." ) ;
363
+ }
364
+ _ => panic ! ( "Expected InvalidArgumentError" ) ,
365
+ }
346
366
}
347
367
348
368
#[ test]
0 commit comments