Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arrow/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions arrow/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down