Skip to content

GH-812: Fix appending to an empty UnionVector - #1292

Open
hutiefang76 wants to merge 2 commits into
apache:mainfrom
hutiefang76:frank/arrow-java-812-empty-union
Open

GH-812: Fix appending to an empty UnionVector#1292
hutiefang76 wants to merge 2 commits into
apache:mainfrom
hutiefang76:frank/arrow-java-812-empty-union

Conversation

@hutiefang76

Copy link
Copy Markdown

What's Changed

Appending to a newly created UnionVector repeatedly reallocates its type buffer until allocation fails: its value capacity remains zero until it has child vectors. Check the type buffer capacity at this stage, since the existing append loop creates and expands the child vectors afterward.

The regression appends two floats to an empty union with a bounded allocator. It fails before the change with an allocation error and passes afterward. All 32 TestVectorAppender tests pass with both the Netty and Unsafe allocators on JDK 21. Checkstyle and Spotless also pass.

Closes #812.

Validation (JDK 21):

mvn -B -pl vector -am test -Dtest=TestVectorAppender -Dsurefire.failIfNoSpecifiedTests=false
mvn -B -pl vector spotless:check

Developed with AI assistance; the regression was verified to fail before the fix and pass afterward.

@github-actions

This comment has been minimized.

@hutiefang76

Copy link
Copy Markdown
Author

The PR-format job failed because the required category label is missing. This is a bug fix for #812 with no breaking API change. Could a maintainer add bug-fix? My account does not have permission to add repository labels.

@lidavidm lidavidm added the bug-fix PRs that fix a big. label Sep 14, 2026
@lidavidm
lidavidm requested a lite review from Copilot September 14, 2026 04:12
@github-actions github-actions Bot added this to the 20.0.0 milestone Sep 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review issues remain.

Pull request overview

Fixes appending to an empty UnionVector by sizing from type-buffer capacity before child vectors are created.

Changes:

  • Updates union capacity expansion logic.
  • Adds bounded-allocator regression coverage.
File summaries
File Description
vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java Adds regression coverage for appending floats to an empty union.
vector/src/main/java/org/apache/arrow/vector/util/VectorAppender.java Corrects union type-buffer capacity handling.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


// make sure there is enough capacity
while (targetUnionVector.getValueCapacity() < newValueCount) {
// Child vectors are created and expanded below; an empty union has zero value capacity.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Child vectors are created and expanded below; an empty union has zero value capacity.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in ea411ff. This revision only removes the comment; the implementation and regression test are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VectorAppender fails with OversizedAllocationException when appending to empty UnionVector

3 participants