We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug
We can create invalid UnionArrays when using try_new(...) as the validation checks done are not strict enough.
try_new(...)
To Reproduce
Run test:
#[test] fn test_invalid_type_ids() { let int_array = Arc::new(Int32Array::from(vec![5, 6])); let f32_array = Arc::new(Float64Array::from(vec![10.0])); let type_ids = [1_i8, 0, 2]; // child with type ID '2' does not exist let offsets = [0_i32, 0, 0]; let type_id_buffer = Buffer::from_slice_ref(type_ids); let value_offsets_buffer = Buffer::from_slice_ref(offsets); let children: Vec<(Field, Arc<dyn Array>)> = vec![ (Field::new("A", DataType::Int32, false), int_array), (Field::new("B", DataType::Float64, false), f32_array), ]; let array = UnionArray::try_new( &[0, 1, 2], type_id_buffer, Some(value_offsets_buffer), children, ) .unwrap(); dbg!(&array); dbg!(array.len()); dbg!(array.value(2)); }
Get output:
arrow-rs$ cargo test -p arrow-array --lib array::union_array::tests::test_invalid_type_ids -- --exact --nocapture Finished test [unoptimized + debuginfo] target(s) in 0.05s Running unittests src/lib.rs (target/debug/deps/arrow_array-d885d14cd41402de) running 1 test [arrow-array/src/array/union_array.rs:851:9] &array = UnionArray(Dense) [ -- type id buffer: ScalarBuffer([1, 0, 2]) -- offsets buffer: ScalarBuffer([0, 0, 0]) -- child 0: "A" (Int32) PrimitiveArray<Int32> [ 5, 6, ] -- child 1: "B" (Float64) PrimitiveArray<Float64> [ 10.0, ] ] [arrow-array/src/array/union_array.rs:852:9] array.len() = 3 thread 'array::union_array::tests::test_invalid_type_ids' panicked at arrow-array/src/array/union_array.rs:232:9: assertion failed: (type_id as usize) < self.fields.len() note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace test array::union_array::tests::test_invalid_type_ids ... FAILED failures: failures: array::union_array::tests::test_invalid_type_ids test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 427 filtered out; finished in 0.00s error: test failed, to rerun pass `-p arrow-array --lib`
Expected behavior
Array should fail to create. It suggests an array with length 3 was created but panics when trying to fetch the 2nd index.
Additional context
Note that some of the documentation is misleading too. For example, on new_unchecked(...):
new_unchecked(...)
arrow-rs/arrow-array/src/array/union_array.rs
Lines 127 to 129 in 9f36c88
However this is contradicted by the following tests:
Lines 740 to 769 in 9f36c88
type_ids
arrow-rs/arrow/tests/array_transform.rs
Lines 485 to 497 in 9f36c88
Edit: another note is that field_type_ids isn't clearly documented on what exactly it represents
field_type_ids
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
We can create invalid UnionArrays when using
try_new(...)
as the validation checks done are not strict enough.To Reproduce
Run test:
Get output:
Expected behavior
Array should fail to create. It suggests an array with length 3 was created but panics when trying to fetch the 2nd index.
Additional context
Note that some of the documentation is misleading too. For example, on
new_unchecked(...)
:arrow-rs/arrow-array/src/array/union_array.rs
Lines 127 to 129 in 9f36c88
new_unchecked(...)
, it implies these inputs are validated bytry_new(...)
However this is contradicted by the following tests:
arrow-rs/arrow-array/src/array/union_array.rs
Lines 740 to 769 in 9f36c88
type_ids
bufferarrow-rs/arrow/tests/array_transform.rs
Lines 485 to 497 in 9f36c88
type_ids
bufferEdit: another note is that
field_type_ids
isn't clearly documented on what exactly it representsThe text was updated successfully, but these errors were encountered: