zeroshade commented on code in PR #578:
URL: https://github.com/apache/iceberg-go/pull/578#discussion_r2382903926


##########
table/metadata.go:
##########
@@ -1421,6 +1443,38 @@ func (c *commonMetadata) checkRefsExist() error {
        return nil
 }
 
+func (c *commonMetadata) validateChronologicalSnapshotLogs() error {
+       for i := 1; i < len(c.SnapshotLog); i++ {
+               prev, cur := c.SnapshotLog[i-1], c.SnapshotLog[i]
+               if (cur.TimestampMs - prev.TimestampMs) < -oneMinuteInMs {
+                       return fmt.Errorf("%w: expected sorted snapshot log 
entries", ErrInvalidMetadata)
+               }
+               if i == len(c.SnapshotLog)-1 {
+                       if c.LastUpdatedMS-cur.TimestampMs < -oneMinuteInMs {
+                               return fmt.Errorf("%w: invalid update timestamp 
%d: before last snapshot log entry at %d", ErrInvalidMetadata, c.LastUpdatedMS, 
cur.TimestampMs)
+                       }
+               }
+       }

Review Comment:
   Can we just use https://pkg.go.dev/slices#IsSortedFunc?



##########
table/metadata.go:
##########
@@ -1421,6 +1443,38 @@ func (c *commonMetadata) checkRefsExist() error {
        return nil
 }
 
+func (c *commonMetadata) validateChronologicalSnapshotLogs() error {
+       for i := 1; i < len(c.SnapshotLog); i++ {
+               prev, cur := c.SnapshotLog[i-1], c.SnapshotLog[i]
+               if (cur.TimestampMs - prev.TimestampMs) < -oneMinuteInMs {
+                       return fmt.Errorf("%w: expected sorted snapshot log 
entries", ErrInvalidMetadata)
+               }
+               if i == len(c.SnapshotLog)-1 {
+                       if c.LastUpdatedMS-cur.TimestampMs < -oneMinuteInMs {
+                               return fmt.Errorf("%w: invalid update timestamp 
%d: before last snapshot log entry at %d", ErrInvalidMetadata, c.LastUpdatedMS, 
cur.TimestampMs)
+                       }
+               }
+       }
+
+       return nil
+}
+
+func (c *commonMetadata) validateChronologicalMetadataLogs() error {
+       for i := 1; i < len(c.MetadataLog); i++ {
+               prev, cur := c.MetadataLog[i-1], c.MetadataLog[i]
+               if (cur.TimestampMs - prev.TimestampMs) < -oneMinuteInMs {
+                       return fmt.Errorf("%w: expected sorted metadata log 
entries", ErrInvalidMetadata)
+               }
+               if i == len(c.MetadataLog)-1 {
+                       if c.LastUpdatedMS-cur.TimestampMs < -oneMinuteInMs {
+                               return fmt.Errorf("%w: invalid update timestamp 
%d: before last metadata log entry at %d", ErrInvalidMetadata, c.LastUpdatedMS, 
cur.TimestampMs)
+                       }
+               }
+       }

Review Comment:
   same as above, can we use https://pkg.go.dev/slices#IsSortedFunc?



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