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 1e0e0c62 fix(compute/exprs): avoid empty field reference panic (#1130)
1e0e0c62 is described below

commit 1e0e0c6236208ac84a2062e3d2499116a62fc8d2
Author: Minh Vu <[email protected]>
AuthorDate: Tue Aug 11 17:51:46 2026 +0200

    fix(compute/exprs): avoid empty field reference panic (#1130)
    
    ### Rationale for this change
    
    A field reference against an empty schema tries to include out.Type in
    the error before out has been set. This causes a nil pointer panic
    instead of returning ErrNoChildren.
    
    ### What changes are included in this PR?
    
    Return ErrNoChildren for an empty schema before formatting a field type.
    Preserve the existing error detail for nested references and add
    regression coverage.
    
    ### Are these changes tested?
    
    - `go test ./arrow/compute/exprs`
    
    ### Are there any user-facing changes?
    
    Invalid field references now return an error instead of panicking when
    the schema has no fields.
---
 arrow/compute/exprs/exec_test.go  | 17 +++++++++++++++++
 arrow/compute/exprs/field_refs.go |  3 +++
 2 files changed, 20 insertions(+)

diff --git a/arrow/compute/exprs/exec_test.go b/arrow/compute/exprs/exec_test.go
index 5348d513..4c986c9d 100644
--- a/arrow/compute/exprs/exec_test.go
+++ b/arrow/compute/exprs/exec_test.go
@@ -340,6 +340,23 @@ func TestExecuteFieldRef(t *testing.T) {
        }
 }
 
+func TestGetRefFieldEmptySchema(t *testing.T) {
+       _, err := exprs.GetRefField(expr.NewStructFieldRef(0), nil)
+       assert.ErrorIs(t, err, compute.ErrNoChildren)
+}
+
+func TestGetRefFieldNestedNoChildren(t *testing.T) {
+       ref := &expr.StructFieldRef{
+               Field: 0,
+               Child: expr.NewStructFieldRef(0),
+       }
+       fields := []arrow.Field{{Name: "value", Type: 
arrow.PrimitiveTypes.Int32}}
+
+       _, err := exprs.GetRefField(ref, fields)
+       assert.ErrorIs(t, err, compute.ErrNoChildren)
+       assert.EqualError(t, err, compute.ErrNoChildren.Error()+": int32")
+}
+
 func TestExecuteScalarFuncCall(t *testing.T) {
        mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
        fromJSON := func(ty arrow.DataType, json string) arrow.Array {
diff --git a/arrow/compute/exprs/field_refs.go 
b/arrow/compute/exprs/field_refs.go
index 5febb91d..6a23abc2 100644
--- a/arrow/compute/exprs/field_refs.go
+++ b/arrow/compute/exprs/field_refs.go
@@ -49,6 +49,9 @@ func GetRefField(ref expr.ReferenceSegment, fields 
[]arrow.Field) (*arrow.Field,
 
        for ref != nil {
                if len(fields) == 0 {
+                       if out == nil {
+                               return nil, compute.ErrNoChildren
+                       }
                        return nil, fmt.Errorf("%w: %s", compute.ErrNoChildren, 
out.Type)
                }
 

Reply via email to