nssalian commented on issue #2062: URL: https://github.com/apache/iceberg-go/issues/2062#issuecomment-7055195624
A question to settle before the PR that removes the clone helpers. With https://github.com/apache/iceberg-go/pull/2655, callers can no longer set a nested type's fields, but they can still overwrite the whole value through a pointer they kept: inner := iceberg.NewStructType(iceberg.NestedField{ID: 2, Name: "x", ...}) // pass inner into NewSchema as field 1, named "s" *inner = iceberg.StructType{} After that, field 1 is an empty struct and `FindFieldByName("s.x")` returns false. A `FindFieldByID(2)` lookup that was cached before the overwrite still returns the old field, so the two lookups disagree. A `SchemaVisitor` can do the same thing, because `Visit` passes the schema's own `NestedField.Type` (via `asStructRef`, `schema.go:379`). The `main` branch behaves the same way today. The clones on `Fields()` and `Field(i)` protect reads only. Which way do we want to go? 1. Constructors deep-copy nested types, and `Visit` hands out copies. 2. Document that types passed into a schema are shared and must not be overwritten. CC: @laskoviymishka @zeroshade -- 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]
