Skip to content

Commit 95e4553

Browse files
committed
change error message to only have up to 10 unique data types
and also change the data type order to appear in the same order as the arrays for easier debugging
1 parent fd03ad3 commit 95e4553

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

arrow-select/src/concat.rs

+26-21
Original file line numberDiff line numberDiff line change
@@ -223,30 +223,35 @@ pub fn concat(arrays: &[&dyn Array]) -> Result<ArrayRef, ArrowError> {
223223

224224
let d = arrays[0].data_type();
225225
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+
}
239248

240-
// Only sort in tests to make the error message is deterministic
241-
#[cfg(test)]
242-
names.sort();
249+
error_message.push_str(").");
243250

244-
names.join(", ")
251+
error_message
245252
};
246253

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));
250255
}
251256

252257
match d {
@@ -368,7 +373,7 @@ mod tests {
368373
&PrimitiveArray::<Int32Type>::from(vec![Some(-1), Some(2), None]),
369374
]);
370375

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).");
372377
}
373378

374379
#[test]

0 commit comments

Comments
 (0)