Skip to content

Commit

Permalink
Improve handling of struct fields
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nl5887 committed Jun 10, 2022
1 parent 8d787d9 commit 48f025c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion arrow/src/compute/kernels/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn concat(arrays: &[&dyn Array]) -> Result<ArrayRef> {

if arrays
.iter()
.any(|array| array.data_type() != arrays[0].data_type())
.any(|array| !array.data_type().equals_datatype(arrays[0].data_type()))
{
return Err(ArrowError::InvalidArgumentError(
"It is not possible to concatenate arrays of different data types."
Expand Down
15 changes: 11 additions & 4 deletions arrow/src/datatypes/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,17 @@ impl DataType {
&& a.data_type().equals_datatype(b.data_type())
}
(DataType::Struct(a), DataType::Struct(b)) => {
a.len() == b.len()
&& a.iter().zip(b).all(|(a, b)| {
a.is_nullable() == b.is_nullable()
&& a.data_type().equals_datatype(b.data_type())
a.iter().all(|a| {
match b.iter().find(|f|f.name().eq(a.name())) {
Some(b) => a.is_nullable() == b.is_nullable() && a.data_type().equals_datatype(b.data_type()),
None => a.is_nullable(),
}
})
&& b.iter().all(|b| {
match a.iter().find(|f|f.name().eq(b.name())) {
Some(a) => a.is_nullable() == b.is_nullable() && a.data_type().equals_datatype(b.data_type()),
None => b.is_nullable(),
}
})
}
(
Expand Down

0 comments on commit 48f025c

Please sign in to comment.