Skip to content

Commit

Permalink
ARROW-4968: [Rust] Assert that struct array field types match data in…
Browse files Browse the repository at this point in the history
… From<> method

I initially thought this might also be an issue in the StructBuilder, but I can't reproduce it, so I'm only adding a fix for `StructArray::From<Vec<Field>, Vec<ArrayRef>>`

Author: Krisztián Szűcs <[email protected]>
Author: Neville Dipale <[email protected]>

Closes apache#4176 from nevi-me/ARROW-4968 and squashes the following commits:

46cd09e <Krisztián Szűcs> remove unnecessary test code
2bf0dd4 <Neville Dipale> ARROW-4968:  Assert that struct array field types match data in From<> method
  • Loading branch information
kszucs committed Apr 19, 2019
1 parent 2b5add5 commit 933cd3c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions rust/arrow/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,11 @@ impl From<Vec<(Field, ArrayRef)>> for StructArray {
field_values[i].len(),
"all child arrays of a StructArray must have the same length"
);
assert_eq!(
field_types[i].data_type(),
field_values[i].data().data_type(),
"the field data types must match the array data in a StructArray"
)
}

let data = ArrayData::builder(DataType::Struct(field_types))
Expand Down Expand Up @@ -1748,6 +1753,24 @@ mod tests {
assert_eq!(0, struct_array.offset());
}

#[test]
#[should_panic(
expected = "the field data types must match the array data in a StructArray"
)]
fn test_struct_array_from_mismatched_types() {
StructArray::from(vec![
(
Field::new("b", DataType::Int16, false),
Arc::new(BooleanArray::from(vec![false, false, true, true]))
as Arc<Array>,
),
(
Field::new("c", DataType::Utf8, false),
Arc::new(Int32Array::from(vec![42, 28, 19, 31])),
),
]);
}

#[test]
fn test_struct_array_slice() {
let boolean_data = ArrayData::builder(DataType::Boolean)
Expand Down

0 comments on commit 933cd3c

Please sign in to comment.