Skip to content
Closed
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
10 changes: 10 additions & 0 deletions go/arrow/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ func (sc *Schema) FieldIndices(n string) []int {
return sc.index[n]
}

// FieldIndex return index of the unique field with the given name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: returns the index

Also, is there a reason to have this in addition to the existing FieldIndices method? A consumer could just do the same length check and use index 0 themselves.

// Returns -1 if the name isn’t found or there are several fields with the given name.
func (sc *Schema) FieldIndex(name string) int {
indices := sc.index[name]
if len(indices) != 1 {
return -1
}
return indices[0]
}

func (sc *Schema) HasField(n string) bool { return len(sc.FieldIndices(n)) > 0 }
func (sc *Schema) HasMetadata() bool { return len(sc.meta.keys) > 0 }

Expand Down
9 changes: 9 additions & 0 deletions go/arrow/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ func TestSchema(t *testing.T) {
}
}

if s.FieldIndex("dup") != -1 {
t.Fatalf("invalid FieldIndex(dup): got=%d, want=-1", s.FieldIndex("dup"))
}
if s.HasField("f1") {
if s.FieldIndex("f1") != 0 {
t.Fatalf("invalid FieldIndex(f1): got=%d, want=0", s.FieldIndex("f1"))
}
}

if got, want := s.String(), tc.serialize; got != want {
t.Fatalf("invalid stringer: got=%q, want=%q", got, want)
}
Expand Down