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 ad2fe2b4 fix(compute): release temporary arrays in binary view casts
(#898)
ad2fe2b4 is described below
commit ad2fe2b481177d70d9fec687d766ab1fe17731d3
Author: Minh Vu <[email protected]>
AuthorDate: Sat Jul 18 19:00:46 2026 +0200
fix(compute): release temporary arrays in binary view casts (#898)
CastBinaryToBinaryView and CastBinaryViewToBinary transferred their
temporary result's buffers via ArraySpan.TakeOwnership (which retains) but
never released the temporary array, leaking a reference on every cast. Release
each temporary after the ownership transfer; the output keeps its retained
ownership, so cast behavior is unchanged.
---
arrow/compute/cast_test.go | 28 ++++++++++++++++++++++
.../compute/internal/kernels/binary_view_casts.go | 2 ++
2 files changed, 30 insertions(+)
diff --git a/arrow/compute/cast_test.go b/arrow/compute/cast_test.go
index 8cb495cb..ae0229a3 100644
--- a/arrow/compute/cast_test.go
+++ b/arrow/compute/cast_test.go
@@ -31,6 +31,7 @@ import (
"github.com/apache/arrow-go/v18/arrow/array"
"github.com/apache/arrow-go/v18/arrow/bitutil"
"github.com/apache/arrow-go/v18/arrow/compute"
+ "github.com/apache/arrow-go/v18/arrow/compute/exec"
"github.com/apache/arrow-go/v18/arrow/decimal128"
"github.com/apache/arrow-go/v18/arrow/decimal256"
"github.com/apache/arrow-go/v18/arrow/internal/testing/gen"
@@ -1679,6 +1680,33 @@ func (c *CastSuite) TestBinaryViewToBinaryLike() {
})
}
+func (c *CastSuite) TestBinaryToBinaryViewReleasesTemporaryResult() {
+ in, _, err := array.FromJSON(c.mem, arrow.BinaryTypes.Binary,
strings.NewReader(`["aGk=", "dGhpcyBpcyB0aGUgZmlyc3QgdGVzdCE=", null]`))
+ c.Require().NoError(err)
+
+ scope := memory.NewCheckedAllocatorScope(c.mem)
+ ctx := exec.WithAllocator(context.Background(), c.mem)
+
+ out, err := compute.CastArray(ctx, in,
compute.SafeCastOptions(arrow.BinaryTypes.BinaryView))
+ c.Require().NoError(err)
+ out.Release()
+ scope.CheckSize(c.T())
+ in.Release()
+}
+
+func (c *CastSuite) TestBinaryViewToBinaryReleasesTemporaryResult() {
+ in := c.buildStringViewArray([]string{"a", "short", "this is a longer
cast value"}, nil)
+
+ scope := memory.NewCheckedAllocatorScope(c.mem)
+ ctx := exec.WithAllocator(context.Background(), c.mem)
+
+ out, err := compute.CastArray(ctx, in,
compute.SafeCastOptions(arrow.BinaryTypes.LargeBinary))
+ c.Require().NoError(err)
+ out.Release()
+ scope.CheckSize(c.T())
+ in.Release()
+}
+
// TestBinaryViewToBinaryView covers cross-view casts (binary_view <->
// string_view) and identity casts. These are zero-copy except for UTF-8
// validation in the binary_view -> string_view direction.
diff --git a/arrow/compute/internal/kernels/binary_view_casts.go
b/arrow/compute/internal/kernels/binary_view_casts.go
index 42d222c4..01a5c384 100644
--- a/arrow/compute/internal/kernels/binary_view_casts.go
+++ b/arrow/compute/internal/kernels/binary_view_casts.go
@@ -200,6 +200,7 @@ func CastBinaryToBinaryView(ctx *exec.KernelCtx, batch
*exec.ExecSpan, out *exec
appendBinaryValues(arr, getVal, ba)
result := ba.bldr.NewArray()
+ defer result.Release()
out.TakeOwnership(result.Data())
return nil
}
@@ -253,6 +254,7 @@ func CastBinaryViewToBinary[OutOffsetT int32 | int64](ctx
*exec.KernelCtx, batch
appendBinaryValues(arr, getVal, ba)
result := ba.bldr.NewArray()
+ defer result.Release()
out.TakeOwnership(result.Data())
return nil
}