You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "zeroshade (via GitHub)" <gi...@apache.org> on 2023/06/09 19:15:31 UTC

[GitHub] [arrow] zeroshade commented on a diff in pull request #36015: GH-36014: [Go] Allow duplicate field names in structs

zeroshade commented on code in PR #36015:
URL: https://github.com/apache/arrow/pull/36015#discussion_r1224669623


##########
go/arrow/datatype_nested.go:
##########
@@ -309,17 +309,28 @@ func (t *StructType) Fields() []Field {
 
 func (t *StructType) Field(i int) Field { return t.fields[i] }
 
+// FieldByName gets the field with the given name.
+//
+// If there are multiple fields with the given name, FieldByName
+// returns the first such field.
 func (t *StructType) FieldByName(name string) (Field, bool) {
 	i, ok := t.index[name]
 	if !ok {
 		return Field{}, false
 	}
-	return t.fields[i], true
+	return t.fields[i[0]], true
 }
 
+// FieldIdx gets the index of the field with the given name.
+//
+// If there are multiple fields with the given name, FieldIdx returns
+// the index of the first first such field.
 func (t *StructType) FieldIdx(name string) (int, bool) {
 	i, ok := t.index[name]
-	return i, ok
+	if ok {
+		return i[0], true
+	}
+	return -1, false
 }

Review Comment:
   We should add a new method that will return the []int by name lookup



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org