This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new e296e326 fix(schema): Fix bug in Schema.HighestFieldId for List types
(#611)
e296e326 is described below
commit e296e326b63abdcd4f375f72260343806e31cd06
Author: Alex Nagel <[email protected]>
AuthorDate: Mon Oct 27 16:33:58 2025 -0400
fix(schema): Fix bug in Schema.HighestFieldId for List types (#611)
## Description
This pull request fixes a bug in computing the `HighestFieldID` when a
schema contains list types. The `findLastFieldID` visitor previously
would only return the computed highest field of a list's element.
Instead, it should return the max of the `ElementID` and the computed
highest field ID of the element field.
Since primitive types trivially have zero-valued field IDs, this would
always return zero for those types. Even if the type were non-primitive,
it would break if IDs were not assigned using preorder traversal (though
of course preorder is recommended).
## Testing
Added a new test case in `schema_test.go` to validate the minimum
reproducible example for this bug.
---
schema_test.go | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/schema_test.go b/schema_test.go
index 69e80b5f..c4ea21a6 100644
--- a/schema_test.go
+++ b/schema_test.go
@@ -905,3 +905,20 @@ func TestHighestFieldID(t *testing.T) {
id := tableSchemaNested.HighestFieldID()
assert.Equal(t, 22, id, "expected highest field ID to be 22, got %d",
id)
}
+
+// TestHighestFieldIDListType tests that HighestFieldID correctly computes
+// the highest field ID in a schema that includes a ListType as the final
field.
+func TestHighestFieldIDListType(t *testing.T) {
+ tableSchema := iceberg.NewSchemaWithIdentifiers(1,
+ []int{1},
+ iceberg.NestedField{
+ ID: 1, Name: "list_field", Type: &iceberg.ListType{
+ ElementID: 2,
+ Element: iceberg.PrimitiveTypes.String,
+ ElementRequired: true,
+ },
+ Required: true,
+ },
+ )
+ assert.Equal(t, 2, tableSchema.HighestFieldID())
+}