Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions arrow/compute/cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions arrow/compute/internal/kernels/binary_view_casts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Loading