Skip to content

Commit 1018067

Browse files
committed
feat: add to concat different data types error message the data types
1 parent 66498b4 commit 1018067

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

arrow-select/src/concat.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use arrow_array::*;
3737
use arrow_buffer::{ArrowNativeType, BooleanBufferBuilder, NullBuffer, OffsetBuffer};
3838
use arrow_data::transform::{Capacities, MutableArrayData};
3939
use arrow_schema::{ArrowError, DataType, FieldRef, SchemaRef};
40-
use std::sync::Arc;
40+
use std::{collections::HashSet, sync::Arc};
4141

4242
fn binary_capacity<T: ByteArrayType>(arrays: &[&dyn Array]) -> Capacities {
4343
let mut item_capacity = 0;
@@ -223,8 +223,22 @@ 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+
unique
234+
.iter()
235+
.map(|dt| format!("{dt}"))
236+
.collect::<Vec<_>>()
237+
.join(", ")
238+
};
239+
226240
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})."),
228242
));
229243
}
230244

@@ -342,7 +356,13 @@ mod tests {
342356
&PrimitiveArray::<Int64Type>::from(vec![Some(-1), Some(2), None]),
343357
&StringArray::from(vec![Some("hello"), Some("bar"), Some("world")]),
344358
]);
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+
}
346366
}
347367

348368
#[test]

0 commit comments

Comments
 (0)