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 d332ffac fix(arrow/scalar): support boolean identity casts (#1102)
d332ffac is described below

commit d332ffaceb8158929b4f98797abc8d734775c38e
Author: Minh Vu <[email protected]>
AuthorDate: Fri Aug 7 18:11:55 2026 +0200

    fix(arrow/scalar): support boolean identity casts (#1102)
    
    ### Rationale for this change
    
    Boolean scalars support casts to numeric and string types, but an
    identity cast to bool currently returns an error.
    
    ### What changes are included in this PR?
    
    Handle the identity case before the other conversions. Cover both valid
    and null Boolean scalars.
    
    ### 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/scalar.go      |  4 ++++
 arrow/scalar/scalar_test.go | 14 ++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/arrow/scalar/scalar.go b/arrow/scalar/scalar.go
index dff4c2ed..68b841d7 100644
--- a/arrow/scalar/scalar.go
+++ b/arrow/scalar/scalar.go
@@ -174,6 +174,10 @@ func (s *Boolean) String() string {
 }
 
 func (s *Boolean) CastTo(dt arrow.DataType) (Scalar, error) {
+       if arrow.TypeEqual(s.DataType(), dt) {
+               return s, nil
+       }
+
        if !s.Valid {
                return MakeNullScalar(dt), nil
        }
diff --git a/arrow/scalar/scalar_test.go b/arrow/scalar/scalar_test.go
index 32555ae3..4cde29a2 100644
--- a/arrow/scalar/scalar_test.go
+++ b/arrow/scalar/scalar_test.go
@@ -186,6 +186,20 @@ func TestBinaryScalarBasics(t *testing.T) {
        assert.True(t, scalar.Equals(value2, value3))
 }
 
+func TestBooleanScalarIdentityCast(t *testing.T) {
+       for _, value := range []bool{false, true} {
+               src := scalar.NewBooleanScalar(value)
+               got, err := src.CastTo(arrow.FixedWidthTypes.Boolean)
+               require.NoError(t, err)
+               assert.Same(t, src, got)
+       }
+
+       null := scalar.MakeNullScalar(arrow.FixedWidthTypes.Boolean)
+       got, err := null.CastTo(arrow.FixedWidthTypes.Boolean)
+       require.NoError(t, err)
+       assert.Same(t, null, got)
+}
+
 func TestBinaryScalarValidateErrors(t *testing.T) {
        sc := scalar.NewBinaryScalar(memory.NewBufferBytes([]byte("xxx")), 
arrow.BinaryTypes.Binary)
        sc.Valid = false

Reply via email to