Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DEMO) tests pass when validate_full is forced #987

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions arrow/src/array/array_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,9 +1211,7 @@ mod tests {
}

#[test]
#[should_panic(
expected = "FixedSizeBinaryArray can only be created from FixedSizeList<u8> arrays"
)]
#[should_panic(expected = "Expected Binary but child data had UInt32")]
fn test_fixed_size_binary_array_from_incorrect_list_array() {
let values: [u32; 12] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
let values_data = ArrayData::builder(DataType::UInt32)
Expand All @@ -1222,15 +1220,15 @@ mod tests {
.build()
.unwrap();

let array_data = unsafe {
ArrayData::builder(DataType::FixedSizeList(
Box::new(Field::new("item", DataType::Binary, false)),
4,
))
.len(3)
.add_child_data(values_data)
.build_unchecked()
};
let array_data = ArrayData::builder(DataType::FixedSizeList(
Box::new(Field::new("item", DataType::Binary, false)),
4,
))
.len(3)
.add_child_data(values_data)
.build()
.unwrap();

let list_array = FixedSizeListArray::from(array_data);
drop(FixedSizeBinaryArray::from(list_array));
}
Expand Down Expand Up @@ -1375,4 +1373,34 @@ mod tests {
assert_eq!(2, arr.value_length());
assert_eq!(5, arr.len())
}

#[test]
fn test_binary_array_all_null() {
let data = vec![None];
let array = BinaryArray::from(data);
array
.data()
.validate_full()
.expect("All null array has valid array data");
}

#[test]
fn test_large_binary_array_all_null() {
let data = vec![None];
let array = LargeBinaryArray::from(data);
array
.data()
.validate_full()
.expect("All null array has valid array data");
}

#[test]
fn fixed_size_binary_array_all_null() {
let data = vec![None] as Vec<Option<String>>;
let array = FixedSizeBinaryArray::try_from_sparse_iter(data.into_iter()).unwrap();
array
.data()
.validate_full()
.expect("All null array has valid array data");
}
}
13 changes: 5 additions & 8 deletions arrow/src/array/array_boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,11 @@ mod tests {
}

#[test]
#[should_panic(expected = "BooleanArray data should contain a single buffer only \
(values buffer)")]
#[should_panic(expected = "Expected 1 buffers in array of type Boolean, got 0")]
fn test_boolean_array_invalid_buffer_len() {
let data = unsafe {
ArrayData::builder(DataType::Boolean)
.len(5)
.build_unchecked()
};
drop(BooleanArray::from(data));
ArrayData::builder(DataType::Boolean)
.len(5)
.build()
.unwrap();
}
}
10 changes: 10 additions & 0 deletions arrow/src/array/array_dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,14 @@ mod tests {
assert_eq!(1, keys.value(2));
assert_eq!(0, keys.value(5));
}

#[test]
fn test_dictionary_all_nulls() {
let test = vec![None, None, None];
let array: DictionaryArray<Int32Type> = test.into_iter().collect();
array
.data()
.validate_full()
.expect("All null array has valid array data");
}
}
73 changes: 32 additions & 41 deletions arrow/src/array/array_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ mod tests {

#[test]
#[should_panic(
expected = "FixedSizeListArray child array length should be a multiple of 3"
expected = "Values length 8 is less than the length (3) multiplied by the value size (3) for FixedSizeList"
)]
fn test_fixed_size_list_array_unequal_children() {
// Construct a value array
Expand All @@ -765,13 +765,12 @@ mod tests {
Box::new(Field::new("item", DataType::Int32, false)),
3,
);
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
.add_child_data(value_data)
.build_unchecked()
};
drop(FixedSizeListArray::from(list_data));

ArrayData::builder(list_data_type)
.len(3)
.add_child_data(value_data)
.build()
.unwrap();
}

#[test]
Expand Down Expand Up @@ -1037,42 +1036,35 @@ mod tests {
}

#[test]
#[should_panic(
expected = "ListArray data should contain a single buffer only (value offsets)"
)]
#[should_panic(expected = "Expected 1 buffers in array of type")]
fn test_list_array_invalid_buffer_len() {
let value_data = unsafe {
ArrayData::builder(DataType::Int32)
.len(8)
.add_buffer(Buffer::from_slice_ref(&[0, 1, 2, 3, 4, 5, 6, 7]))
.build_unchecked()
};
let value_data = ArrayData::builder(DataType::Int32)
.len(8)
.add_buffer(Buffer::from_slice_ref(&[0, 1, 2, 3, 4, 5, 6, 7]))
.build()
.unwrap();

let list_data_type =
DataType::List(Box::new(Field::new("item", DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
.add_child_data(value_data)
.build_unchecked()
};
drop(ListArray::from(list_data));

ArrayData::builder(list_data_type)
.len(3)
.add_child_data(value_data)
.build()
.unwrap();
}

#[test]
#[should_panic(
expected = "ListArray should contain a single child array (values array)"
)]
#[should_panic(expected = "should contain 1 child data array(s), had 0")]
fn test_list_array_invalid_child_array_len() {
let value_offsets = Buffer::from_slice_ref(&[0, 2, 5, 7]);
let list_data_type =
DataType::List(Box::new(Field::new("item", DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
.add_buffer(value_offsets)
.build_unchecked()
};
drop(ListArray::from(list_data));
ArrayData::builder(list_data_type)
.len(3)
.add_buffer(value_offsets)
.build()
.unwrap();
}

#[test]
Expand Down Expand Up @@ -1126,13 +1118,12 @@ mod tests {

let list_data_type =
DataType::List(Box::new(Field::new("item", DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.add_buffer(buf2)
.add_child_data(value_data)
.build_unchecked()
};
drop(ListArray::from(list_data));

ArrayData::builder(list_data_type)
.add_buffer(buf2)
.add_child_data(value_data)
.build()
.unwrap();
}

#[test]
Expand Down
25 changes: 8 additions & 17 deletions arrow/src/array/array_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,7 @@ impl<T: ArrowTimestampType> PrimitiveArray<T> {
/// Constructs a `PrimitiveArray` from an array data reference.
impl<T: ArrowPrimitiveType> From<ArrayData> for PrimitiveArray<T> {
fn from(data: ArrayData) -> Self {
assert_eq!(
data.buffers().len(),
1,
"PrimitiveArray data should contain a single buffer only (values buffer)"
);

// safety: ArrayData was checked for validity on construction
let ptr = data.buffers()[0].as_ptr();
Self {
data,
Expand Down Expand Up @@ -947,19 +942,15 @@ mod tests {
}

#[test]
#[should_panic(expected = "PrimitiveArray data should contain a single buffer only \
(values buffer)")]
#[should_panic(expected = "Expected 1 buffers in array of type Int32, got 2")]
fn test_primitive_array_invalid_buffer_len() {
let buffer = Buffer::from_slice_ref(&[0i32, 1, 2, 3, 4]);
let data = unsafe {
ArrayData::builder(DataType::Int32)
.add_buffer(buffer.clone())
.add_buffer(buffer)
.len(5)
.build_unchecked()
};

drop(Int32Array::from(data));
ArrayData::builder(DataType::Int32)
.add_buffer(buffer.clone())
.add_buffer(buffer)
.len(5)
.build()
.unwrap();
}

#[test]
Expand Down
21 changes: 15 additions & 6 deletions arrow/src/array/array_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,22 @@ mod tests {
}

#[test]
fn test_string_array_from_string_vec() {
let data = vec!["Foo".to_owned(), "Bar".to_owned(), "Baz".to_owned()];
fn test_string_array_all_null() {
let data = vec![None];
let array = StringArray::from(data);
array
.data()
.validate_full()
.expect("All null array has valid array data");
}

assert_eq!(array.len(), 3);
assert_eq!(array.value(0), "Foo");
assert_eq!(array.value(1), "Bar");
assert_eq!(array.value(2), "Baz");
#[test]
fn test_large_string_array_all_null() {
let data = vec![None];
let array = LargeStringArray::from(data);
array
.data()
.validate_full()
.expect("All null array has valid array data");
}
}
Loading