RussellSpitzer commented on a change in pull request #3039:
URL: https://github.com/apache/iceberg/pull/3039#discussion_r764992345



##########
File path: core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java
##########
@@ -101,6 +101,53 @@ public static Snapshot oldestAncestor(Table table) {
     return ancestorsOf(start, lookup);
   }
 
+  /**
+   * Traverses the history of the table's current snapshot
+   * and finds the oldest ancestor snapshot after or equal to the timestamp in 
milliseconds.
+   *
+   * @param table           a table
+   * @param timestampMillis a timestamp in milliseconds
+   * @return the first snapshot from the given timestamp, or null if the 
current snapshot is older than the timestamp
+   * @throws IllegalStateException if the first snapshot from the given time 
can't be determined
+   */
+  public static Snapshot oldestAncestorFrom(Table table, Long timestampMillis) 
{
+    Snapshot currentSnapshot = table.currentSnapshot();
+    long timestamp = timestampMillis == null ? -1L : timestampMillis;
+    // If no snapshot exists or timestamp is higher than the current snapshot
+    if (currentSnapshot == null || currentSnapshot.timestampMillis() < 
timestamp) {
+      return null;
+    }
+
+    // Traverse to the oldest snapshot after or equal to the timestamp

Review comment:
       This looks like it is now
   
   "The oldest snapshot that was not created after the timestamp" - which would 
be good in the docs ^ too
   
   Like
   ```
   Given [10, 11, 12, 13, 14]
   oldestAncestor(x <=10) = null
   oldestAncestor(11)  = 11
   oldestAncestor(14) = 14
   oldestAncestor(x > 14) = 14
   ```




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