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 02020e03 fix(arrow/scalar): format extension values from storage 
scalars (#1111)
02020e03 is described below

commit 02020e03e486681a4325f5aadb2749b0b6984e85
Author: Minh Vu <[email protected]>
AuthorDate: Fri Aug 7 20:43:21 2026 +0200

    fix(arrow/scalar): format extension values from storage scalars (#1111)
    
    ### Rationale for this change
    
    Extension.String tries to cast the extension scalar to utf8, but
    Extension.CastTo only accepts the same extension type. Valid extension
    scalars therefore return three dots.
    
    ### What changes are included in this PR?
    
    Use the storage scalar's string representation for valid extension
    values and keep null extensions formatted as null.
    
    ### 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      | 5 ++---
 arrow/scalar/scalar_test.go | 5 +++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/arrow/scalar/scalar.go b/arrow/scalar/scalar.go
index 68b841d7..5b9bcac1 100644
--- a/arrow/scalar/scalar.go
+++ b/arrow/scalar/scalar.go
@@ -477,11 +477,10 @@ func (s *Extension) String() string {
        if !s.Valid {
                return "null"
        }
-       val, err := s.CastTo(arrow.BinaryTypes.String)
-       if err != nil {
+       if s.Value == nil {
                return "..."
        }
-       return string(val.(*String).Value.Bytes())
+       return s.Value.String()
 }
 
 func NewExtensionScalar(storage Scalar, typ arrow.DataType) *Extension {
diff --git a/arrow/scalar/scalar_test.go b/arrow/scalar/scalar_test.go
index 4cde29a2..16366a7d 100644
--- a/arrow/scalar/scalar_test.go
+++ b/arrow/scalar/scalar_test.go
@@ -110,6 +110,11 @@ func 
TestNullExtensionScalarValidateRejectsNonNullStorage(t *testing.T) {
        assert.ErrorContains(t, sc.ValidateFull(), "non-null storage value")
 }
 
+func TestExtensionScalarStringUsesStorageValue(t *testing.T) {
+       sc := scalar.NewExtensionScalar(scalar.NewInt16Scalar(42), 
types.NewSmallintType())
+       assert.Equal(t, "42", sc.String())
+}
+
 func TestMakeScalarUint(t *testing.T) {
        three := scalar.MakeScalar(uint(3))
        assert.NoError(t, three.ValidateFull())

Reply via email to