You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "yevgenypats (via GitHub)" <gi...@apache.org> on 2023/04/24 20:43:44 UTC

[GitHub] [arrow] yevgenypats commented on a diff in pull request #35307: GH-35306: Fix Schema.Fields() to return copy of fields

yevgenypats commented on code in PR #35307:
URL: https://github.com/apache/arrow/pull/35307#discussion_r1175764172


##########
go/arrow/schema.go:
##########
@@ -194,7 +194,11 @@ func (sc *Schema) WithEndianness(e endian.Endianness) *Schema {
 func (sc *Schema) Endianness() endian.Endianness { return sc.endianness }
 func (sc *Schema) IsNativeEndian() bool          { return sc.endianness == endian.NativeEndian }
 func (sc *Schema) Metadata() Metadata            { return sc.meta }
-func (sc *Schema) Fields() []Field               { return sc.fields }
+func (sc *Schema) Fields() []Field { 
+	fields := make([]Field, len(sc.fields))
+	copy(fields, sc.fields)
+	return fields
+}

Review Comment:
   We can do that but currently all methods return copy of things - like `Metadata` for example and `Field(i)` apart from this one (which also bit me in our code as I wasn't expecting the returned value to change the internal state)



##########
go/arrow/schema.go:
##########
@@ -194,7 +194,11 @@ func (sc *Schema) WithEndianness(e endian.Endianness) *Schema {
 func (sc *Schema) Endianness() endian.Endianness { return sc.endianness }
 func (sc *Schema) IsNativeEndian() bool          { return sc.endianness == endian.NativeEndian }
 func (sc *Schema) Metadata() Metadata            { return sc.meta }
-func (sc *Schema) Fields() []Field               { return sc.fields }
+func (sc *Schema) Fields() []Field { 
+	fields := make([]Field, len(sc.fields))
+	copy(fields, sc.fields)
+	return fields
+}

Review Comment:
   We can do that but currently all methods return copy of things - like `Metadata` for example and `Field(i)` apart from this one (which also bitten me in our code as I wasn't expecting the returned value to change the internal state)



-- 
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