prochac opened a new issue, #682:
URL: https://github.com/apache/iceberg-go/issues/682

   ### Apache Iceberg version
   
   main (development)
   
   ### Please describe the bug 🐞
   
   > What I get
   
   When I have duplicates in my schema, it panics
   
   > What I expect
   
   return Go error
   
   ```go
   package iceberg
   
   import (
        "testing"
   
        "github.com/apache/iceberg-go"
        "github.com/apache/iceberg-go/table"
   )
   
   func Test_table_NewMetadata(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.StringType{},
                }
        }
        icebergSchema := iceberg.NewSchema(1, fields...)
   
        defer func() {
                r := recover()
                if r != nil {
                        t.Errorf("Unexpected error: %v", r)
                }
        }()
   
        metadata, err := table.NewMetadata(
                icebergSchema,
                &iceberg.PartitionSpec{},
                table.UnsortedSortOrder,
                "",
                iceberg.Properties{},
        )
        if err != nil {
                t.Fatal(err)
        }
        _ = metadata
   }
   ```
   The returned error is:
   ```
   Unexpected error: invalid schema: field with id 1 not found, this is a bug, 
please report.
   ```
   But we could easily get a much nicer error frm  
`(iceberg.Schema).lazyIDToName` func:
   ```
   error encountered during schema visitor: invalid schema: multiple fields for 
name foo: 1 and 3
   ```
   Yet, it's swallowed in `(iceberg.Schema).FindColumnName`, and then the panic 
is thrown in `table.checkSchemaCompatibility` func.
   
   
   I'm aware it's my mistake, use schema with duplicate keys. But it shouldn't 
crash the app.


-- 
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]

Reply via email to