Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ func (s *Schema) MarshalJSON() ([]byte, error) {

type Alias Schema

aliasCopy := *(*Alias)(s)
aliasCopy.IdentifierFieldIDs = ids
aliasCopy := Alias{ID: s.ID, IdentifierFieldIDs: ids}

return json.Marshal(struct {
Type string `json:"type"`
Expand Down
46 changes: 46 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"testing"

"github.com/apache/iceberg-go"
Expand Down Expand Up @@ -2293,3 +2294,48 @@ func TestVisitGeoSchemaWithSchemaVisitorPerPrimitiveType(t *testing.T) {
assert.Equal(t, 1, v.geometryCalls)
assert.Equal(t, 1, v.geographyCalls)
}

func TestSchemaMarshalJSONConcurrentLazyLookups(t *testing.T) {
for range 32 {
schema := iceberg.NewSchemaWithIdentifiers(17, nil,
iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int64, Required: true},
iceberg.NestedField{ID: 2, Name: "data", Type: iceberg.PrimitiveTypes.String},
)
start := make(chan struct{})
var wg sync.WaitGroup
for range 8 {
wg.Go(func() {
<-start
for range 8 {
_, err := json.Marshal(schema)
assert.NoError(t, err)
}
})
wg.Go(func() {
<-start
_, found := schema.FindFieldByID(1)
assert.True(t, found)
_, found = schema.FindFieldByName("data")
assert.True(t, found)
_, found = schema.FindFieldByNameCaseInsensitive("DATA")
assert.True(t, found)
name, found := schema.FindColumnName(2)
assert.True(t, found)
assert.Equal(t, "data", name)
})
}
close(start)
wg.Wait()

data, err := json.Marshal(schema)
require.NoError(t, err)
assert.JSONEq(t, `{
"type": "struct", "schema-id": 17, "identifier-field-ids": [],
"fields": [
{"id": 1, "name": "id", "type": "long", "required": true},
{"id": 2, "name": "data", "type": "string", "required": false}
]
}`, string(data))
assert.Nil(t, schema.IdentifierFieldIDs)
}
}
Loading
Loading