This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git
The following commit(s) were added to refs/heads/main by this push:
new 8a09b917 fix(array): avoid allocating for ReserveData(0) (#895)
8a09b917 is described below
commit 8a09b917bcb4f76153259c1ce0ef39a947f4aaf3
Author: Minh Vu <[email protected]>
AuthorDate: Sat Jul 18 18:54:56 2026 +0200
fix(array): avoid allocating for ReserveData(0) (#895)
BinaryViewBuilder.ReserveData always delegated to the block builder, so
ReserveData(0) created a full default data block even when every value remained
inline. Return early on zero-length reservations so no unused variadic data
buffer is allocated; positive reservations and the public API are unchanged.
Integration JSON expectations are updated accordingly.
---
arrow/array/binary_test.go | 7 +++++++
arrow/array/binarybuilder.go | 3 +++
arrow/internal/arrjson/arrjson_test.go | 12 ++++--------
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/arrow/array/binary_test.go b/arrow/array/binary_test.go
index 0e27b9bb..8e91860d 100644
--- a/arrow/array/binary_test.go
+++ b/arrow/array/binary_test.go
@@ -732,6 +732,13 @@ func TestBinaryViewBuilderRejectsOversizedValues(t
*testing.T) {
})
}
+func TestBinaryViewBuilderReserveData0DoesNotAllocate(t *testing.T) {
+ b := NewBinaryViewBuilder(binaryViewNoAllocAllocator{})
+ defer b.Release()
+
+ b.ReserveData(0)
+}
+
func TestBinaryViewStringRoundTrip(t *testing.T) {
mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
defer mem.AssertSize(t, 0)
diff --git a/arrow/array/binarybuilder.go b/arrow/array/binarybuilder.go
index 698e7c53..07114df9 100644
--- a/arrow/array/binarybuilder.go
+++ b/arrow/array/binarybuilder.go
@@ -476,6 +476,9 @@ func checkBinaryViewValueSize(length int64) {
func (b *BinaryViewBuilder) ReserveData(length int) {
checkBinaryViewValueSize(int64(length))
+ if length == 0 {
+ return
+ }
b.blockBuilder.Reserve(int(length))
}
diff --git a/arrow/internal/arrjson/arrjson_test.go
b/arrow/internal/arrjson/arrjson_test.go
index 7e2f386f..232270b9 100644
--- a/arrow/internal/arrjson/arrjson_test.go
+++ b/arrow/internal/arrjson/arrjson_test.go
@@ -6186,8 +6186,7 @@ func makeViewTypesWantJSONs() string {
"SIZE": 1,
"INLINED": "35"
}
- ],
- "VARIADIC_DATA_BUFFERS": [""]
+ ]
},
{
"name": "string_view",
@@ -6220,8 +6219,7 @@ func makeViewTypesWantJSONs() string {
"SIZE": 1,
"INLINED": "5"
}
- ],
- "VARIADIC_DATA_BUFFERS": [""]
+ ]
}
]
},
@@ -6259,8 +6257,7 @@ func makeViewTypesWantJSONs() string {
"SIZE": 4,
"INLINED": "35353535"
}
- ],
- "VARIADIC_DATA_BUFFERS": [""]
+ ]
},
{
"name": "string_view",
@@ -6378,8 +6375,7 @@ func makeViewTypesWantJSONs() string {
"SIZE": 2,
"INLINED": "55"
}
- ],
- "VARIADIC_DATA_BUFFERS": [""]
+ ]
}
]
}