Repository: apache/iceberg-go
Pull request #320 (2025-03-05 17:05:54)

feat(table): add GetType for requirements


Patch:
diff --git a/catalog/catalog.go b/catalog/catalog.go
index a241110..6b2118f 100644
--- a/catalog/catalog.go
+++ b/catalog/catalog.go
@@ -37,6 +37,7 @@ import (
 
 	"github.com/apache/iceberg-go"
 	"github.com/apache/iceberg-go/catalog/internal"
+	iceinternal "github.com/apache/iceberg-go/internal"
 	"github.com/apache/iceberg-go/table"
 )
 
@@ -196,7 +197,7 @@ func getUpdatedPropsAndUpdateSummary(currentProps iceberg.Properties, removals [
 	summary := PropertiesUpdateSummary{
 		Removed: removed,
 		Updated: updated,
-		Missing: iceberg.Difference(removals, removed),
+		Missing: iceinternal.Difference(removals, removed),
 	}
 
 	return updatedProps, summary, nil
diff --git a/internal/utils.go b/internal/utils.go
new file mode 100644
index 0000000..ced65cb
--- /dev/null
+++ b/internal/utils.go
@@ -0,0 +1,35 @@
+// 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 internal
+
+// Helper function to find the difference between two slices (a - b).
+func Difference(a, b []string) []string {
+	m := make(map[string]bool)
+	for _, item := range b {
+		m[item] = true
+	}
+
+	diff := make([]string, 0)
+	for _, item := range a {
+		if !m[item] {
+			diff = append(diff, item)
+		}
+	}
+
+	return diff
+}
diff --git a/table/requirements.go b/table/requirements.go
index 57cac63..3ea3255 100644
--- a/table/requirements.go
+++ b/table/requirements.go
@@ -41,6 +41,7 @@ const (
 type Requirement interface {
 	// Validate checks that the current table metadata satisfies the requirement.
 	Validate(Metadata) error
+	GetType() string
 }
 
 // baseRequirement is a common struct that all requirements embed. It is used to
@@ -49,6 +50,10 @@ type baseRequirement struct {
 	Type string `json:"type"`
 }
 
+func (b baseRequirement) GetType() string {
+	return b.Type
+}
+
 type assertCreate struct {
 	baseRequirement
 }
@@ -123,16 +128,17 @@ func (a *assertRefSnapshotID) Validate(meta Metadata) error {
 			break
 		}
 	}
-	if r == nil {
-		return fmt.Errorf("requirement failed: branch or tag %s is missing, expected %d", a.Ref, a.SnapshotID)
-	}
 
-	if a.SnapshotID == nil {
-		return fmt.Errorf("requirement failed: %s %s was created concurrently", r.SnapshotRefType, a.Ref)
-	}
+	if r != nil {
+		if a.SnapshotID == nil {
+			return fmt.Errorf("requirement failed: %s %s was created concurrently", r.SnapshotRefType, a.Ref)
+		}
 
-	if r.SnapshotID != *a.SnapshotID {
-		return fmt.Errorf("requirement failed: %s %s has changed: expected id %d, found %d", r.SnapshotRefType, a.Ref, a.SnapshotID, r.SnapshotID)
+		if r.SnapshotID != *a.SnapshotID {
+			return fmt.Errorf("requirement failed: %s %s has changed: expected id %d, found %d", r.SnapshotRefType, a.Ref, a.SnapshotID, r.SnapshotID)
+		}
+	} else if a.SnapshotID != nil {
+		return fmt.Errorf("requirement failed: branch or tag %s is missing, expected %d", a.Ref, a.SnapshotID)
 	}
 
 	return nil
diff --git a/utils.go b/utils.go
index b35b768..4fae972 100644
--- a/utils.go
+++ b/utils.go
@@ -206,20 +206,3 @@ func (l literalSet) All(fn func(Literal) bool) bool {
 
 	return true
 }
-
-// Helper function to find the difference between two slices (a - b).
-func Difference(a, b []string) []string {
-	m := make(map[string]bool)
-	for _, item := range b {
-		m[item] = true
-	}
-
-	diff := make([]string, 0)
-	for _, item := range a {
-		if !m[item] {
-			diff = append(diff, item)
-		}
-	}
-
-	return diff
-}


Test patch:
diff --git a/utils_test.go b/internal/utils_test.go
similarity index 95%
rename from utils_test.go
rename to internal/utils_test.go
index 9f4f888..a90b3eb 100644
--- a/utils_test.go
+++ b/internal/utils_test.go
@@ -15,11 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package iceberg
+package internal_test
 
 import (
 	"testing"
 
+	"github.com/apache/iceberg-go/internal"
 	"github.com/stretchr/testify/require"
 )
 
@@ -71,7 +72,7 @@ func TestDifference(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			assert := require.New(t)
-			result := Difference(tt.a, tt.b)
+			result := internal.Difference(tt.a, tt.b)
 			assert.ElementsMatch(tt.expected, result)
 		})
 	}