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 996f3865 fix(arrow/compute/exprs): name the full reference in the 
field type mismatch error (#1561)
996f3865 is described below

commit 996f3865b12ae846c13d2f44712300b9b24ffe5f
Author: Harrison Crosse <[email protected]>
AuthorDate: Mon Nov 16 12:56:08 2026 -0500

    fix(arrow/compute/exprs): name the full reference in the field type 
mismatch error (#1561)
    
    ### Rationale for this change
    
    When a bound field reference has the wrong type,
    `ExecuteScalarExpression` returns an error that names the wrong field or
    none. I bound `col` as `int64` over `int32` data at top level and
    `col.a` the same way inside a struct. Both schemas have a leading `int8`
    column `x`. On v18.8.0 and main, I got:
    
    ```text
    invalid: referenced field %!s(<nil>) was int32, but should have been int64
    invalid: referenced field .field(0) was int32, but should have been int64
    ```
    
    The full references are `.field(1)` and `.field(1).field(0)`. Arrow C++
    names the whole reference in the same error:
    
    
    
https://github.com/apache/arrow/blob/976779b2aac587f51b87c3bd2e6ae4c36f75ab6c/cpp/src/arrow/compute/expression.cc#L763-L765
    
    ### What changes are included in this PR?
    
    `execFieldRef` strips the first struct field segment to find the column,
    and the error formatted what was left. It now formats the original
    `e.Reference`.
    
    ### Are these changes tested?
    
    `TestFieldRefTypeMismatchReleases` gains a `wantMsg` column for its top
    level and nested rows. Both rows fail on main and pass with this change.
    
    With Go 1.26.10, vet and race tests for `arrow/compute/...`,
    `golangci-lint` 2.13.2 and the Release Audit Tool passed.
    
    ### Are there any user-facing changes?
    
    Yes. Type mismatch errors now name the full field reference. There is no
    API change.
---
 arrow/compute/exprs/exec.go      | 2 +-
 arrow/compute/exprs/exec_test.go | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arrow/compute/exprs/exec.go b/arrow/compute/exprs/exec.go
index 19ffe737..5fffa8c3 100644
--- a/arrow/compute/exprs/exec.go
+++ b/arrow/compute/exprs/exec.go
@@ -551,7 +551,7 @@ func execFieldRef(ctx context.Context, e 
*expr.FieldReference, input compute.Exe
                                out.Release()
                        }
                        return nil, fmt.Errorf("%w: referenced field %s was %s, 
but should have been %s",
-                               arrow.ErrInvalid, ref, dt, expectedType)
+                               arrow.ErrInvalid, e.Reference, dt, expectedType)
                }
        }
 
diff --git a/arrow/compute/exprs/exec_test.go b/arrow/compute/exprs/exec_test.go
index 5944a95b..d9276328 100644
--- a/arrow/compute/exprs/exec_test.go
+++ b/arrow/compute/exprs/exec_test.go
@@ -867,11 +867,13 @@ func TestFieldRefTypeMismatchReleases(t *testing.T) {
                exprType, dataType arrow.DataType
                json               string
                path               []any
+               wantMsg            string
        }{
                {"top level", arrow.BinaryTypes.String, 
arrow.PrimitiveTypes.Int32,
-                       `[{"col": 1}, {"col": 2}]`, []any{"col"}},
+                       `[{"col": 1}, {"col": 2}]`, []any{"col"}, "referenced 
field .field(0) was int32"},
                {"nested", structOf(arrow.BinaryTypes.String), 
structOf(arrow.PrimitiveTypes.Int32),
-                       `[{"col": {"a": 1}}, {"col": {"a": 2}}]`, []any{"col", 
"a"}},
+                       `[{"col": {"a": 1}}, {"col": {"a": 2}}]`, []any{"col", 
"a"},
+                       "referenced field .field(0).field(0) was int32"},
        }
 
        for _, tt := range tests {
@@ -894,6 +896,7 @@ func TestFieldRefTypeMismatchReleases(t *testing.T) {
                        ctx := compute.WithAllocator(context.Background(), mem)
                        result, err := exprs.ExecuteScalarExpression(ctx, 
dataSchema, e, compute.NewDatumWithoutOwning(rec))
                        assert.ErrorIs(t, err, arrow.ErrInvalid)
+                       assert.ErrorContains(t, err, tt.wantMsg)
                        assert.Nil(t, result)
                })
        }

Reply via email to