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 64f20c62 fix(schema): Fix HighestFieldID to include ListType ElementID
(#609)
64f20c62 is described below
commit 64f20c6258337448c2d63e5bd77e586db1adc5c1
Author: Blue Li <[email protected]>
AuthorDate: Fri Oct 24 01:29:24 2025 +0800
fix(schema): Fix HighestFieldID to include ListType ElementID (#609)
## Fix HighestFieldID to include ListType ElementID
The `findLastFieldID` visitor was ignoring `ListType.ElementID`, causing
`HighestFieldID()` to return incorrect values.
**Changes:**
- Fixed `findLastFieldID.List()` to include `field.ElementID` in
calculation
- Updated test cases to validate the fix
---
schema.go | 4 +++-
schema_test.go | 27 ++++++++++++++++++++++++++-
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/schema.go b/schema.go
index 74150058..0e2e0537 100644
--- a/schema.go
+++ b/schema.go
@@ -1089,7 +1089,9 @@ func (findLastFieldID) Field(field NestedField,
fieldResult int) int {
return max(field.ID, fieldResult)
}
-func (findLastFieldID) List(_ ListType, elemResult int) int { return
elemResult }
+func (findLastFieldID) List(field ListType, elemResult int) int {
+ return max(field.ElementID, elemResult)
+}
func (findLastFieldID) Map(field MapType, keyResult, valueResult int) int {
return max(field.KeyID, field.ValueID, keyResult, valueResult)
diff --git a/schema_test.go b/schema_test.go
index ce5ea72b..69e80b5f 100644
--- a/schema_test.go
+++ b/schema_test.go
@@ -97,6 +97,16 @@ var (
},
Required: false,
},
+ iceberg.NestedField{
+ ID: 21,
+ Name: "tags",
+ Type: &iceberg.ListType{
+ ElementID: 22,
+ Element: iceberg.PrimitiveTypes.String,
+ ElementRequired: false,
+ },
+ Required: false,
+ },
)
tableSchemaSimple = iceberg.NewSchemaWithIdentifiers(1,
@@ -222,6 +232,8 @@ func TestSchemaIndexByIDVisitor(t *testing.T) {
}, Required: false},
19: {ID: 19, Name: "key", Type: iceberg.PrimitiveTypes.String,
Required: true},
20: {ID: 20, Name: "value", Type: iceberg.PrimitiveTypes.Int32,
Required: true},
+ 21: tableSchemaNested.Field(8),
+ 22: {ID: 22, Name: "element", Type:
iceberg.PrimitiveTypes.String, Required: false},
}, index)
}
@@ -252,6 +264,8 @@ func TestSchemaIndexByName(t *testing.T) {
"thing": 18,
"thing.key": 19,
"thing.value": 20,
+ "tags": 21,
+ "tags.element": 22,
}, index)
}
@@ -866,6 +880,17 @@ func TestSchemaRoundTrip(t *testing.T) {
"value": "int",
"value-required": true
}
+ },
+ {
+ "id": 21,
+ "name": "tags",
+ "required": false,
+ "type": {
+ "type": "list",
+ "element-id": 22,
+ "element-required": false,
+ "element": "string"
+ }
}
]
}`, string(data))
@@ -878,5 +903,5 @@ func TestSchemaRoundTrip(t *testing.T) {
func TestHighestFieldID(t *testing.T) {
id := tableSchemaNested.HighestFieldID()
- assert.Equal(t, 20, id, "expected highest field ID to be 20, got %d",
id)
+ assert.Equal(t, 22, id, "expected highest field ID to be 22, got %d",
id)
}