Skip to content

MutableArrayData::try_extend_nulls panics on empty union input #11198

Closed

Description

@Jefffrey

Describe the bug

let first_type_id = fields
.iter()
.next()
.expect("union must have at least one field")
.0;

let first_type_id = fields
.iter()
.next()
.expect("union must have at least one field")
.0;

it assumes a non-empty unionfields, but an empty union is valid

To Reproduce

reproduction from codex:

// arrow-data/src/transform/mod.rs
    #[test]
    fn empty_union_extend_zero_nulls() {
        use arrow_schema::UnionFields;

        for mode in [UnionMode::Sparse, UnionMode::Dense] {
            let mut builder = ArrayData::builder(DataType::Union(UnionFields::empty(), mode))
                .len(0)
                .add_buffer(Buffer::from_vec(Vec::<i8>::new()));

            if mode == UnionMode::Dense {
                builder = builder.add_buffer(Buffer::from_vec(Vec::<i32>::new()));
            }

            let source = builder.build().unwrap();
            let mut mutable = MutableArrayData::new(vec![&source], true, 0);

            mutable.try_extend_nulls(0);
        }
    }

Expected behavior

this should not panic. need to consider what expected behaviour is though, as there are no child type ids to extend 🤔

Additional context

No response

Activity

  1. added theissue type on Sep 24, 2026
  2. added a commit that references this issue on Oct 18, 2026
    f53b221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions