Skip to content

GH-45722: [C++] Add UnsafeAppendEmptyValue(s) to array builders - #55818

Open
CyberKun wants to merge 1 commit into
apache:mainfrom
CyberKun:GH-45722-unsafe-append-empty-value
Open

CyberKun wants to merge 1 commit into
apache:mainfrom
CyberKun:GH-45722-unsafe-append-empty-value

Conversation

@CyberKun

Copy link
Copy Markdown

Rationale for this change

This is the first step towards #45722 (adding UnsafeAppend methods to StructBuilder). In #47522, reviewers pointed out that a struct null also needs an "empty value" added to each child builder, and there was no unsafe way to do that. pitrou suggested starting with a separate PR that adds UnsafeAppendEmptyValue() and UnsafeAppendEmptyValues() to all builders, so that's what this PR does.

What changes are included in this PR?

  • ArrayBuilder gets two new virtual methods, UnsafeAppendEmptyValue() and UnsafeAppendEmptyValues(int64_t). They do the same thing as AppendEmptyValue(s) but skip the capacity check, so the caller must call Reserve() first.
  • Builders where this can be done without allocating now have a fast version: null, numeric, boolean, binary/string, binary view, fixed-size binary, list/large list/list view, fixed-size list, and struct.
  • For fixed-size list and struct, the empty values also go into the child builders, so the caller has to reserve space in the children too. I wrote this in the doc comments.
  • Where possible, the existing AppendEmptyValue(s) methods now just call Reserve() and then the unsafe version, as pitrou suggested in GH-45722: [C++] Add UnsafeAppend methods to StructBuilder #47522.
  • Some builders can't do this without allocating: adaptive int, dictionary, run-end encoded, union, and map. These use a default in ArrayBuilder that calls the safe method.

Are these changes tested?

Yes. I added TestArray.TestUnsafeAppendEmptyValue, which goes through the types in TestArrayUtilitiesAgainstTheseTypes() plus a nested struct. For each type it builds one array with the safe methods and one with reserve plus the unsafe methods, then checks that they're equal. All arrow-array-test tests pass locally (Ubuntu 24.04, GCC 13, Debug build).

Are there any user-facing changes?

Yes, two new public methods on ArrayBuilder and its subclasses. Existing code keeps working.

Questions for reviewers

  1. I gave the base methods a default (calling the safe method and aborting if it fails) so that subclasses of ArrayBuilder outside Arrow don't break. Would you rather have them pure virtual?
  2. This PR only covers the first step of [C++] StructBuilder should have UnsafeAppend methods #45722. Should it have its own issue?

AI usage

I used an AI coding assistant (Kiro) to explore the builder code and to draft the implementation and the test. I reviewed every change, checked the design decisions above, built it locally, and ran the tests. I also broke the struct change on purpose to confirm the test catches it.

Copilot AI balanced review requested due to automatic review settings November 27, 2026 19:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants