Core: Write null for current-snapshot-id for V3+#12335
Merged
Merged
Conversation
Fokko
commented
Feb 19, 2025
RussellSpitzer
approved these changes
Feb 19, 2025
RussellSpitzer
left a comment
Member
There was a problem hiding this comment.
Minor nit around putting version gating in a constant, lgtm otherwise
nastra
reviewed
Feb 19, 2025
9bc048a to
727ca4a
Compare
nastra
approved these changes
Feb 19, 2025
Contributor
Author
|
Moving this forward, thanks @nastra and @RussellSpitzer |
laskoviymishka
added a commit
to laskoviymishka/iceberg-go
that referenced
this pull request
May 10, 2026
Closes apache#1002. v3 spec requires `"current-snapshot-id": null` for empty tables, not the field omitted entirely (Java apache/iceberg#12335). omitempty on the *int64 field was dropping the key when nil; metadataV3 now has a MarshalJSON that re-injects the key with explicit null after the snapshots field — Java's declaration order — while preserving v1/v2 omitempty behaviour, since v1/v2 fixtures rely on the -1 sentinel. The injection walks the marshaled JSON via json.Decoder so the surrounding field order is preserved (a map round-trip would resort alphabetically and break byte-level diffs against Java-produced metadata.json).
laskoviymishka
added a commit
to laskoviymishka/iceberg-go
that referenced
this pull request
May 10, 2026
Closes apache#1002. v3 spec requires `"current-snapshot-id": null` for empty tables, not the field omitted entirely (Java apache/iceberg#12335). omitempty on the *int64 field was dropping the key when nil; metadataV3 now has a MarshalJSON that re-injects it as explicit null at its canonical declaration-order position — just before the first key that follows it in commonMetadata — so empty-table output stays byte-compatible with Java's metadata.json shape. v1/v2 keep omitempty behaviour, since v1/v2 fixtures rely on the -1 sentinel. The injection walks the marshaled JSON via json.Decoder so the surrounding field order is preserved (a map round-trip would resort alphabetically and break byte-level diffs against Java-produced metadata.json). Same MarshalJSON adds a symmetric guard for last-partition-id, which is required for v2+ per spec but had the same omitempty tag. The parser's preValidate/validate path already enforces non-nil on read; this is the write-side equivalent so direct struct construction that skips the builder can't silently emit a non-conformant file Java/PyIceberg would reject. In practice the builder always sets the field, so the guard only fires on malformed in-memory state.
laskoviymishka
added a commit
to laskoviymishka/iceberg-go
that referenced
this pull request
May 13, 2026
Closes apache#1002. v3 spec requires `"current-snapshot-id": null` for empty tables, not the field omitted entirely (Java apache/iceberg#12335). omitempty on the shared commonMetadata field was dropping the key when nil; metadataV3 now has a MarshalJSON that wraps the type alias inside an outer struct redeclaring CurrentSnapshotID without omitempty, so the field-name collision resolves to the shallower (always-emitted) declaration. v1/v2 keep the omitempty path since their fixtures rely on the -1 sentinel. Same MarshalJSON adds a symmetric guard for last-partition-id, which is required for v2+ per spec but had the same omitempty tag. The parser's preValidate/validate path already enforces non-nil on read; this is the write-side equivalent so direct struct construction that skips the builder can't silently emit a non-conformant file Java/PyIceberg would reject. In practice the builder always sets the field, so the guard only fires on malformed in-memory state.
laskoviymishka
added a commit
to laskoviymishka/iceberg-go
that referenced
this pull request
May 17, 2026
Closes apache#1002. v3 spec requires `"current-snapshot-id": null` for empty tables, not the field omitted entirely (Java apache/iceberg#12335). omitempty on the shared commonMetadata field was dropping the key when nil; metadataV3 now has a MarshalJSON that wraps the type alias inside an outer struct redeclaring CurrentSnapshotID without omitempty, so the field-name collision resolves to the shallower (always-emitted) declaration. v1/v2 keep the omitempty path since their fixtures rely on the -1 sentinel. Same MarshalJSON adds a symmetric guard for last-partition-id, which is required for v2+ per spec but had the same omitempty tag. The parser's preValidate/validate path already enforces non-nil on read; this is the write-side equivalent so direct struct construction that skips the builder can't silently emit a non-conformant file Java/PyIceberg would reject. In practice the builder always sets the field, so the guard only fires on malformed in-memory state.
laskoviymishka
added a commit
to apache/iceberg-go
that referenced
this pull request
May 17, 2026
Closes #1002. v3 spec requires `"current-snapshot-id": null` for empty tables, not the field omitted entirely (Java apache/iceberg#12335). omitempty on the *int64 field was dropping the key when nil; metadataV3 now has a MarshalJSON that re-injects the key with explicit null after the snapshots field — Java's declaration order — while preserving v1/v2 omitempty behaviour, since v1/v2 fixtures rely on the -1 sentinel. The injection walks the marshaled JSON via json.Decoder so the surrounding field order is preserved (a map round-trip would resort alphabetically and break byte-level diffs against Java-produced metadata.json).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See https://lists.apache.org/thread/gqqsnww6nqc50pddwn29blzghmb0m0h3
Closes #12310