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 9645138e fix(arrow/scalar): preserve binary cast target types (#1101)
9645138e is described below
commit 9645138e641176dec39517c6b1fef8d10f7fe41e
Author: Minh Vu <[email protected]>
AuthorDate: Fri Aug 7 18:11:41 2026 +0200
fix(arrow/scalar): preserve binary cast target types (#1101)
### Rationale for this change
Binary.CastTo returns a binary scalar with the source type. This is
incorrect when a large binary or fixed-size binary scalar is cast to
ordinary binary.
### What changes are included in this PR?
Use the requested target type for the result and cover binary, large
binary, and fixed-size binary sources.
### Are these changes tested?
- `go test ./arrow/scalar`
### Are there any user-facing changes?
No API changes. This corrects the reported behavior while preserving the
existing ownership and compatibility contracts.
---
arrow/scalar/binary.go | 2 +-
arrow/scalar/scalar_test.go | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/arrow/scalar/binary.go b/arrow/scalar/binary.go
index 6b11eb3e..60da6072 100644
--- a/arrow/scalar/binary.go
+++ b/arrow/scalar/binary.go
@@ -73,7 +73,7 @@ func (b *Binary) CastTo(to arrow.DataType) (Scalar, error) {
switch to.ID() {
case arrow.BINARY:
- return NewBinaryScalar(b.Value, b.Type), nil
+ return NewBinaryScalar(b.Value, to), nil
case arrow.LARGE_BINARY:
return NewLargeBinaryScalar(b.Value), nil
case arrow.STRING:
diff --git a/arrow/scalar/scalar_test.go b/arrow/scalar/scalar_test.go
index e0084e33..32555ae3 100644
--- a/arrow/scalar/scalar_test.go
+++ b/arrow/scalar/scalar_test.go
@@ -198,6 +198,29 @@ func TestBinaryScalarValidateErrors(t *testing.T) {
assert.Error(t, sc.ValidateFull())
}
+func TestBinaryScalarCastToBinaryUsesTargetType(t *testing.T) {
+ buf := memory.NewBufferBytes([]byte("abc"))
+ defer buf.Release()
+
+ scalars := []scalar.BinaryScalar{
+ scalar.NewBinaryScalar(buf, arrow.BinaryTypes.Binary),
+ scalar.NewLargeBinaryScalar(buf),
+ scalar.NewFixedSizeBinaryScalar(buf,
&arrow.FixedSizeBinaryType{ByteWidth: 3}),
+ }
+ for _, src := range scalars {
+ t.Run(src.DataType().Name(), func(t *testing.T) {
+ defer src.Release()
+
+ got, err := src.CastTo(arrow.BinaryTypes.Binary)
+ require.NoError(t, err)
+ defer got.(scalar.Releasable).Release()
+ assert.IsType(t, &scalar.Binary{}, got)
+ assert.True(t,
arrow.TypeEqual(arrow.BinaryTypes.Binary, got.DataType()))
+ assert.Equal(t, []byte("abc"),
got.(scalar.BinaryScalar).Data())
+ })
+ }
+}
+
func TestStringMakeScalar(t *testing.T) {
assertMakeScalar(t, scalar.NewStringScalar("three"), "three")
assertParseScalar(t, arrow.BinaryTypes.String, "three",
scalar.NewStringScalar("three"))