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 73f27c8d fix(table): no panic in duplicate schema keys (#684)
73f27c8d is described below

commit 73f27c8d0bc3fb4a31cd2869a0f52cd5043b9bd8
Author: ferhat elmas <[email protected]>
AuthorDate: Mon Jan 19 21:34:58 2026 +0100

    fix(table): no panic in duplicate schema keys (#684)
    
    fixes #682
    
    also fixes a typo in file name
    comptability -> compatibility
    
    Signed-off-by: ferhat elmas <[email protected]>
---
 ...ability.go => metadata_schema_compatibility.go} |  4 ++
 table/metadata_schema_compatibility_test.go        | 52 ++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/table/metadata_schema_comptability.go 
b/table/metadata_schema_compatibility.go
similarity index 98%
rename from table/metadata_schema_comptability.go
rename to table/metadata_schema_compatibility.go
index 792b06d2..7d58a29d 100644
--- a/table/metadata_schema_comptability.go
+++ b/table/metadata_schema_compatibility.go
@@ -78,6 +78,10 @@ func checkSchemaCompatibility(sc *iceberg.Schema, 
formatVersion int) error {
                return fmt.Errorf("failed to validate unknown types: %w", err)
        }
 
+       if _, err := iceberg.IndexNameByID(sc); err != nil {
+               return fmt.Errorf("invalid schema: %w", err)
+       }
+
        fieldsIt, err := sc.FlatFields()
        if err != nil {
                return fmt.Errorf("failed to check Schema compatibility: %w", 
err)
diff --git a/table/metadata_schema_compatibility_test.go 
b/table/metadata_schema_compatibility_test.go
new file mode 100644
index 00000000..eb67fe54
--- /dev/null
+++ b/table/metadata_schema_compatibility_test.go
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package table
+
+import (
+       "testing"
+
+       "github.com/apache/iceberg-go"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+func TestNewMetadata_DuplicateValues(t *testing.T) {
+       names := []string{"foo", "bar", "foo"}
+
+       fields := make([]iceberg.NestedField, len(names))
+       for i, name := range names {
+               fields[i] = iceberg.NestedField{
+                       ID:   i + 1,
+                       Name: name,
+                       Type: iceberg.PrimitiveTypes.String,
+               }
+       }
+       icebergSchema := iceberg.NewSchema(1, fields...)
+
+       _, err := NewMetadata(
+               icebergSchema,
+               &iceberg.PartitionSpec{},
+               UnsortedSortOrder,
+               "",
+               iceberg.Properties{},
+       )
+
+       require.Error(t, err)
+       assert.Contains(t, err.Error(), "invalid schema: error encountered 
during schema visitor")
+       assert.Contains(t, err.Error(), "multiple fields for name foo")
+}

Reply via email to