Skip to content

Commit 48f025c

Browse files
committed
Improve handling of struct fields
Currently if the order of fields in struct is different, it will fail. This fix will lookup fields, ignoring the field order and length and fail if not nullable. Array data type comparison will use the equals_datatype instead of comparing enums.
1 parent 8d787d9 commit 48f025c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

arrow/src/compute/kernels/concat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn concat(arrays: &[&dyn Array]) -> Result<ArrayRef> {
6262

6363
if arrays
6464
.iter()
65-
.any(|array| array.data_type() != arrays[0].data_type())
65+
.any(|array| !array.data_type().equals_datatype(arrays[0].data_type()))
6666
{
6767
return Err(ArrowError::InvalidArgumentError(
6868
"It is not possible to concatenate arrays of different data types."

arrow/src/datatypes/datatype.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,17 @@ impl DataType {
684684
&& a.data_type().equals_datatype(b.data_type())
685685
}
686686
(DataType::Struct(a), DataType::Struct(b)) => {
687-
a.len() == b.len()
688-
&& a.iter().zip(b).all(|(a, b)| {
689-
a.is_nullable() == b.is_nullable()
690-
&& a.data_type().equals_datatype(b.data_type())
687+
a.iter().all(|a| {
688+
match b.iter().find(|f|f.name().eq(a.name())) {
689+
Some(b) => a.is_nullable() == b.is_nullable() && a.data_type().equals_datatype(b.data_type()),
690+
None => a.is_nullable(),
691+
}
692+
})
693+
&& b.iter().all(|b| {
694+
match a.iter().find(|f|f.name().eq(b.name())) {
695+
Some(a) => a.is_nullable() == b.is_nullable() && a.data_type().equals_datatype(b.data_type()),
696+
None => b.is_nullable(),
697+
}
691698
})
692699
}
693700
(

0 commit comments

Comments
 (0)