ryanworl opened a new pull request, #1831:
URL: https://github.com/apache/iceberg-go/pull/1831
## What
REST catalogs reject commits that add a sort order under an id that already
exists. `MetadataBuilder.AddSortOrder` still emitted `add-sort-order` when the
order being "added" was already present in the **base** metadata: the existing
guard (`*lastAddedSortOrderID != newOrderID`) only suppresses a second add
within the same builder, and a fresh builder starts with `lastAddedSortOrderID
== nil`, so the first reuse emitted the update.
`SetDefaultSortOrderID` compounded this by encoding `-1` ("last added") even
when no `add-sort-order` preceded it in the update list, so replaying the
emitted updates against a fresh builder could not resolve the default.
- The reuse path now records the id as `lastAddedSortOrderID` and returns
without appending `add-sort-order`.
- `SetDefaultSortOrderID` encodes `-1` only when the update list actually
carries an `add-sort-order` for that id; otherwise it writes the concrete id.
Net effect: setting the default sort order back to an existing order (e.g.
unsorted) produces a commit payload with `set-default-sort-order` carrying the
concrete id and no `add-sort-order`.
## Tests
- `TestAddSortOrderDoesNotAddDuplicateUpdate` updated: reuse of a base order
emits nothing; adding a *new* order twice in one builder still emits exactly
one add.
- New `TestAddSortOrderReuseDoesNotDuplicateUpdate`: unsorted→A→unsorted and
A→B→A; replaying the emitted updates against a fresh builder reproduces the
default.
- `go test ./table/...` and `golangci-lint run` are clean.
Made with [Cursor](https://cursor.com)
--
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]