Commit c576fd1
authored
fix(table): seed UpdateSchema id counter from metadata LastColumnID (#936)
## Problem
`NewUpdateSchema` seeds its fresh-id counter from
`txn.meta.CurrentSchema().HighestFieldID()`. The Iceberg spec reserves
`last-column-id` on table metadata as the monotonic counter for this
purpose; Java's
[`SchemaUpdate`](https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/SchemaUpdate.java)
seeds from `metadata.lastColumnId()`.
When the current schema's highest id is lower than the lifetime max —
after a previous evolution added columns that were later dropped, or
after a schema swap — `AddColumn` allocates ids already referenced by
fields in historical schemas. Catalogs that index the full schema
history (e.g. AWS Glue's `schemasToGlueColumns`) then reject the commit
with a duplicate field id error.
## Fix
Seed `lastColumnID` from `txn.meta.LastColumnID()` in `NewUpdateSchema`.
Adds a public `LastColumnID()` getter on `*MetadataBuilder` — the
`Metadata` interface already exposes this value, but `txn.meta` is the
builder.
`MetadataBuilder.AddSchema` already keeps `last-column-id` monotonic via
`max(b.lastColumnId, schema.HighestFieldID())`, so no other allocator
sites need changes.
## Testing
Adds `TestAddColumnMonotonicFieldIDs`: constructs metadata whose
`last-column-id` exceeds the current schema's `HighestFieldID()` (by
adding a higher-id schema while leaving the original as current) and
asserts that `AddColumn` allocates above `last-column-id`. Confirmed
failing on `main` before the fix and passing after.
`go test ./...` passes.
Fixes #935
Signed-off-by: Ashley Jeffs <ash@jeffail.uk>1 parent f8df330 commit c576fd1
3 files changed
Lines changed: 60 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
299 | 303 | | |
300 | 304 | | |
301 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | | - | |
138 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
139 | 144 | | |
140 | 145 | | |
141 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
913 | 913 | | |
914 | 914 | | |
915 | 915 | | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
0 commit comments