laskoviymishka commented on code in PR #2655:
URL: https://github.com/apache/iceberg-go/pull/2655#discussion_r4666724837
##########
types.go:
##########
@@ -475,28 +477,30 @@ func (s *StructType) Equals(other Type) bool {
return false
}
- return slices.EqualFunc(s.FieldList, st.FieldList, func(a, b
NestedField) bool {
+ return slices.EqualFunc(s.fields, st.fields, func(a, b NestedField)
bool {
return a.Equals(b)
})
}
// NumFields returns the number of fields in the struct.
-func (s *StructType) NumFields() int { return len(s.FieldList) }
+func (s *StructType) NumFields() int { return len(s.fields) }
// Field returns the i-th field of the struct. It panics if i is out of range.
-func (s *StructType) Field(i int) NestedField { return s.FieldList[i] }
+func (s *StructType) Field(i int) NestedField { return s.fields[i] }
// Fields returns a copy of the struct's fields. Changing the returned slice
// does not change the struct. Use NumFields and Field to read the fields
// without copying them.
-func (s *StructType) Fields() []NestedField { return slices.Clone(s.FieldList)
}
+func (s *StructType) Fields() []NestedField { return slices.Clone(s.fields) }
// The JSON methods of the nested types name every serialized field instead of
// encoding through an alias of the type, so the wire format does not depend on
// which Go fields are exported.
-func (s *StructType) MarshalJSON() ([]byte, error) {
- fields := s.FieldList
+// MarshalJSON has a value receiver on purpose: [Schema.AsStruct] returns a
+// StructType value, which must not encode as {}.
Review Comment:
Could this also say the other methods stay on pointer receivers? The mix is
deliberate, but nothing in the enabled linters
([`.golangci.yml`](https://github.com/apache/iceberg-go/blob/426655407a189517a21fbd5ef245c6a78cf1a4de/.golangci.yml#L18-L30))
checks receiver consistency, so a later tidy-up could move the rest over
unnoticed.
```suggestion
// StructType value, which must not encode as {}. The other methods keep
// pointer receivers, so only *StructType, *ListType and *MapType implement
Type.
```
##########
website/src/releases.md:
##########
@@ -64,7 +64,14 @@ Per-release notes (highlights, breaking changes,
contributors) are published on
- **`UpdateSchema` rejects deleting an identifier field.** `DeleteColumn` on
an identifier column used to succeed and quietly drop the column from the
table's identifier fields. Now `Apply` (and `Commit`) fails with `cannot delete
identifier field …`, as in Java. Deleting a struct that contains one already
failed, and now reports `cannot delete field … as it will delete nested
identifier field …`. To delete the column anyway, also call
`SetIdentifierField` with the identifier fields the schema should keep (for
example `SetIdentifierField([][]string{})` to clear them). This also stops a
new column that reuses a deleted identifier column's name from becoming the
identifier.
- **Schema JSON defaults preserve integer precision.** `long` defaults now
decode as `int64` instead of `float64`; non-integral, non-numeric, or
out-of-range values now fail to parse. Numeric literals inside object and list
defaults decode as `json.Number` rather than `float64`.
- **REST mutation keys can enable transport replay.** Namespace, table, view,
transaction and scan-cancellation mutations listed in the [REST catalog
documentation](./configuration.md) now carry fresh UUIDv7 `Idempotency-Key`
headers when `GET /v1/config` returns a non-null `idempotency-key-lifetime`.
Go's HTTP transport may replay certain failed requests on reused connections
with the same key; the advertised lifetime is not yet enforced. Scan plan and
task key handling is unchanged. When a lifetime is advertised, a default
`Idempotency-Key` configured via `WithHeaders` is dropped after `GET
/v1/config`.
-- **`StructType.Fields()` returns a copy.** Changing the returned slice no
longer changes the struct, matching `ListType.Fields()` and `MapType.Fields()`.
Build a new type with `NewStructType` instead. `NumFields()` and `Field(i)`
read fields without copying, and `NewListType` and `NewMapType` are the
constructors for the other nested types. The exported fields are unchanged for
now; they become unexported before v1.0.0 (see
[#2062](https://github.com/apache/iceberg-go/issues/2062)).
+- **`StructType.Fields()` returns a copy.** Changing the returned slice no
longer changes the struct, matching `ListType.Fields()` and `MapType.Fields()`.
Build a new type with `NewStructType` instead. `NumFields()` and `Field(i)`
read fields without copying, and `NewListType` and `NewMapType` are the
constructors for the other nested types. The struct's field list is no longer
exported; see the next note.
+- **Nested type fields are unexported.** `StructType`, `ListType` and
`MapType` can no longer be built with keyed struct literals, and their fields
can no longer be assigned (see
[#2062](https://github.com/apache/iceberg-go/issues/2062)). Build them with
`NewStructType`, `NewListType` and `NewMapType`, and to change one, build a new
value. Read them through methods named after the old fields:
+ - `StructType.FieldList` becomes `Fields()` (a copy), or `NumFields()` and
`Field(i)` to read without copying.
+ - `ListType.ElementID`, `Element` and `ElementRequired` become
`ElementID()`, `Element()` and `ElementRequired()`.
+ - `MapType.KeyID`, `KeyType`, `ValueID`, `ValueType` and `ValueRequired`
become `KeyID()`, `KeyType()`, `ValueID()`, `ValueType()` and `ValueRequired()`.
+ - `Schema.IdentifierFieldIDs` is unexported too and becomes
`IdentifierFieldIDs()`, which returns a copy. Set the IDs with
`NewSchemaWithIdentifiers`, which keeps its own copy of the slice it is given.
+
+ The JSON form of these types and of `Schema` is unchanged.
Review Comment:
Could this say that plain values encode differently now? Pointers and
`Schema` are unchanged, but with the value-receiver `MarshalJSON`,
`json.Marshal(schema.AsStruct())` goes from `{"fields":[...]}` to
`{"type":"struct","fields":[...]}`. List and map values previously dropped
their element, key and value types. A marshal of each form at
[base](https://github.com/apache/iceberg-go/blob/f7dc20dfcf567302c443cc538839bd6421cc7312/types.go#L498)
and head shows the difference.
```suggestion
The JSON form of pointers to these types and of `Schema` is unchanged.
`MarshalJSON` now has a value receiver, so plain values such as
`json.Marshal(schema.AsStruct())` encode the same typed form as pointers; they
used to encode by reflection without `"type"`, and list and map values lost
their element, key and value types.
```
##########
view/metadata_test.go:
##########
@@ -977,7 +977,6 @@ func TestMetadataGettersReturnDefensiveCopies(t *testing.T)
{
currentSchema := md.CurrentSchema()
currentSchema.ID = 99
Review Comment:
Could we keep one identifier-ID check here through the accessor? With the
old line and the matching assert gone, `view` has no end-to-end check on
identifier IDs any more.
[`TestSchemaIdentifierFieldIDsAreCopied`](https://github.com/apache/iceberg-go/blob/426655407a189517a21fbd5ef245c6a78cf1a4de/schema_test.go#L598-L609)
covers the root package only. Something like:
```go
ids := currentSchema.IdentifierFieldIDs()
ids[0] = 99
// ...
assert.Equal(t, []int{1}, md.CurrentSchema().IdentifierFieldIDs())
```
--
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]