CyberKun opened a new pull request, #55818:
URL: https://github.com/apache/arrow/pull/55818

   ### 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 #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 #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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to