@@ -223,30 +223,35 @@ 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
- // Allow unused mut as we need it for tests
234
- #[ allow( unused_mut) ]
235
- let mut names = unique
236
- . into_iter ( )
237
- . map ( |dt| format ! ( "{dt}" ) )
238
- . collect :: < Vec < _ > > ( ) ;
226
+ // Create error message with up to 10 unique data types in the order they appear
227
+ let error_message = {
228
+ // 10 max unique data types to print and another 1 to know if there are more
229
+ let mut unique_data_types = HashSet :: with_capacity ( 11 ) ;
230
+
231
+ let mut error_message =
232
+ format ! ( "It is not possible to concatenate arrays of different data types ({d}" ) ;
233
+ unique_data_types. insert ( d) ;
234
+
235
+ for array in arrays {
236
+ let is_unique = unique_data_types. insert ( array. data_type ( ) ) ;
237
+
238
+ if unique_data_types. len ( ) == 11 {
239
+ error_message. push_str ( ", ..." ) ;
240
+ break ;
241
+ }
242
+
243
+ if is_unique {
244
+ error_message. push_str ( ", " ) ;
245
+ error_message. push_str ( & array. data_type ( ) . to_string ( ) ) ;
246
+ }
247
+ }
239
248
240
- // Only sort in tests to make the error message is deterministic
241
- #[ cfg( test) ]
242
- names. sort ( ) ;
249
+ error_message. push_str ( ")." ) ;
243
250
244
- names . join ( ", " )
251
+ error_message
245
252
} ;
246
253
247
- return Err ( ArrowError :: InvalidArgumentError (
248
- format ! ( "It is not possible to concatenate arrays of different data types ({input_data_types})." ) ,
249
- ) ) ;
254
+ return Err ( ArrowError :: InvalidArgumentError ( error_message) ) ;
250
255
}
251
256
252
257
match d {
@@ -368,7 +373,7 @@ mod tests {
368
373
& PrimitiveArray :: < Int32Type > :: from ( vec ! [ Some ( -1 ) , Some ( 2 ) , None ] ) ,
369
374
] ) ;
370
375
371
- assert_eq ! ( re. unwrap_err( ) . to_string( ) , "Invalid argument error: It is not possible to concatenate arrays of different data types (Int32, Int64, Utf8)." ) ;
376
+ assert_eq ! ( re. unwrap_err( ) . to_string( ) , "Invalid argument error: It is not possible to concatenate arrays of different data types (Int64, Utf8, Int32 )." ) ;
372
377
}
373
378
374
379
#[ test]
0 commit comments