This is an automated email from the ASF dual-hosted git repository.
fokko 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 f28ac59 feat(table): add GetType for requirements (#320)
f28ac59 is described below
commit f28ac5904047253fe305a37f0b116eeac285cf9b
Author: Matt Topol <[email protected]>
AuthorDate: Thu Mar 6 17:29:41 2025 -0500
feat(table): add GetType for requirements (#320)
---
table/requirements.go | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
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