You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ze...@apache.org on 2026/07/27 17:07:24 UTC

(arrow-go) branch main updated: fix(arrow/scalar): handle nil child values in run-end scalars (#1001)

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 abf9187b fix(arrow/scalar): handle nil child values in run-end scalars (#1001)
abf9187b is described below

commit abf9187bb9d2bbbb6806782bcc7f07c877148fea
Author: Minh Vu <vu...@gmail.com>
AuthorDate: Mon Jul 27 19:07:18 2026 +0200

    fix(arrow/scalar): handle nil child values in run-end scalars (#1001)
    
    `MakeNullScalar` creates a null run-end encoded scalar without a child
    value. `RunEndEncoded.Validate` dereferenced that value before checking
    nullness, so validation could panic.
    
    This handles the missing child explicitly: null scalars are accepted,
    malformed non-null scalars still fail, and both paths are covered by
    tests.
    
    Tests: `go test ./arrow/scalar`
---
 arrow/scalar/nested.go      |  7 +++++++
 arrow/scalar/scalar_test.go | 10 ++++++++++
 2 files changed, 17 insertions(+)

diff --git a/arrow/scalar/nested.go b/arrow/scalar/nested.go
index b6adf7f0..5980e9ac 100644
--- a/arrow/scalar/nested.go
+++ b/arrow/scalar/nested.go
@@ -754,6 +754,13 @@ func (s *RunEndEncoded) Release() {
 func (s *RunEndEncoded) value() interface{} { return s.Value.value() }
 
 func (s *RunEndEncoded) Validate() (err error) {
+	if s.Value == nil {
+		if !s.Valid {
+			return nil
+		}
+		return fmt.Errorf("%w: non-null run-end-encoded scalar has no value", arrow.ErrInvalid)
+	}
+
 	if err = s.Value.Validate(); err != nil {
 		return
 	}
diff --git a/arrow/scalar/scalar_test.go b/arrow/scalar/scalar_test.go
index 49ef342f..1d321d47 100644
--- a/arrow/scalar/scalar_test.go
+++ b/arrow/scalar/scalar_test.go
@@ -1789,4 +1789,14 @@ func TestRunEndEncodedNullScalar(t *testing.T) {
 	assert.False(t, sc.IsValid())
 	assert.Truef(t, arrow.TypeEqual(dt, sc.DataType()), "expected: %s\ngot: %s", dt, sc.DataType())
 	assert.IsType(t, (*scalar.RunEndEncoded)(nil), sc)
+	assert.NoError(t, sc.Validate())
+	assert.NoError(t, sc.ValidateFull())
+}
+
+func TestRunEndEncodedScalarValidateRejectsMissingNonNullValue(t *testing.T) {
+	sc := scalar.MakeNullScalar(arrow.RunEndEncodedOf(arrow.PrimitiveTypes.Int16, arrow.BinaryTypes.String)).(*scalar.RunEndEncoded)
+	sc.Valid = true
+
+	assert.ErrorContains(t, sc.Validate(), "has no value")
+	assert.ErrorContains(t, sc.ValidateFull(), "has no value")
 }