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

new_null_array generates an invalid union array #4600

Closed
kawadakk opened this issue Jul 31, 2023 · 1 comment · Fixed by #4601
Closed

new_null_array generates an invalid union array #4600

kawadakk opened this issue Jul 31, 2023 · 1 comment · Fixed by #4601
Labels
arrow Changes to the arrow crate bug

Comments

@kawadakk
Copy link
Contributor

Describe the bug
new_null_array generates a union array that fails validation by ArrayData::validate_full.

To Reproduce
Modify test_null_union as follows:

#[test]
fn test_null_union() {
    for mode in [UnionMode::Sparse, UnionMode::Dense] {
        let data_type = DataType::Union(
            UnionFields::new(
                vec![2, 1],
                vec![
                    Field::new("foo", DataType::Int32, true),
                    Field::new("bar", DataType::Int64, true),
                ],
            ),
            mode,
        );
        let array = new_null_array(&data_type, 4);

        let array = as_union_array(array.as_ref());
        assert_eq!(array.len(), 4);
        assert_eq!(array.null_count(), 0);

        for i in 0..4 {
            let a = array.value(i);
            assert_eq!(a.len(), 1);
            assert_eq!(a.null_count(), 1);
            assert!(a.is_null(0))
        }

        array.to_data().validate_full().unwrap(); // <---- new
    }
}

This will fail with the following output: thread 'array::tests::test_null_union' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidArgumentError("Sparse union child array #1 has length smaller than expected for union array (0 < 4)")', arrow-array\src\array\mod.rs:852:45

Expected behavior
Producing a valid array

Additional context

@tustvold
Copy link
Contributor

label_issue.py automatically added labels {'arrow'} from #4601

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate bug
Projects
None yet
2 participants