Revanth14 opened a new pull request, #2431:
URL: https://github.com/apache/iceberg-go/pull/2431
## Problem
Step 3 of the deep-immutability series in #2062. Before the composite type
fields can be unexported, callers need constructors to replace the
`StructType{}`, `ListType{}` and `MapType{}` literals. They also need a way to
read struct fields without copying. `StructType.Fields()` also returns its
backing slice, so a caller can change the struct through it, unlike
`ListType.Fields()` and `MapType.Fields()`.
## Fix
Adds `NewStructType(fields...)`, `NewListType` and `NewMapType`, which
return pointers. `NewStructType` copies its fields. Adds
`StructType.NumFields()` and `Field(i)`, and `Fields()` now returns a copy. The
one caller that indexed `Fields()[i]` in a loop (`applyChanges.Struct`) uses
`Field(i)` instead. The exported fields stay; same-name accessors for List/Map
can only come once the fields are unexported, as noted in #2062.
## Testing
`TestNestedTypeConstructorsMatchLiterals` checks that each constructor
equals the literal it replaces, including the JSON. That covers a nil field
list still marshaling as `"fields":null`, so the later literal migration is a
no-op. `TestNewStructTypeCopiesFields` and `TestStructTypeFieldsReturnsCopy`
fail when the respective copy is removed. All non-test callers of
`StructType.Fields` were checked with gopls and only read the result.
## Context
Part of #2062. A release note covers the `Fields()` copy.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]