From a5c78e438b48a3ffd3bc1c5de269e68ac37f15b4 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Thu, 30 Jul 2026 21:49:28 +0200 Subject: [PATCH] fix(arrow): return owned fields by name --- arrow/schema.go | 2 +- arrow/schema_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arrow/schema.go b/arrow/schema.go index 806bd0d09..cb99adb59 100644 --- a/arrow/schema.go +++ b/arrow/schema.go @@ -220,7 +220,7 @@ func (sc *Schema) FieldsByName(n string) ([]Field, bool) { return nil, ok } if len(indices) == 1 { - return sc.fields[indices[0] : indices[0]+1], ok + return []Field{sc.fields[indices[0]]}, ok } else if len(indices) > 1 { fields := make([]Field, 0, len(indices)) for _, v := range indices { diff --git a/arrow/schema_test.go b/arrow/schema_test.go index 3cc7b374e..0069e69de 100644 --- a/arrow/schema_test.go +++ b/arrow/schema_test.go @@ -336,6 +336,19 @@ func TestSchema(t *testing.T) { } } +func TestSchemaFieldsByNameReturnsCopy(t *testing.T) { + schema := NewSchema([]Field{{Name: "id", Type: PrimitiveTypes.Int64}}, nil) + fields, ok := schema.FieldsByName("id") + if !ok { + t.Fatal("field not found") + } + fields[0].Name = "changed" + + if got, want := schema.Field(0).Name, "id"; got != want { + t.Fatalf("schema field mutated through returned slice: got %q, want %q", got, want) + } +} + func TestSchemaAddField(t *testing.T) { s := NewSchema([]Field{ {Name: "f1", Type: PrimitiveTypes.Int32},