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



##########
File path: core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java
##########
@@ -65,12 +65,18 @@ public static boolean ancestorOf(Table table, long 
snapshotId, long ancestorSnap
   }
 
   /**
-   * Traverses the history of the table's current snapshot and finds the 
oldest Snapshot.
-   * @return null if there is no current snapshot in the table, else the 
oldest Snapshot.
+   * Traverses the history of the table's current snapshot
+   * and finds the oldest Snapshot after or equal to the timestamp in 
milliseconds.
+   * @return null if there is no current snapshot in the table,
+   * else the oldest Snapshot after or equal to the timestamp in milliseconds.
    */
-  public static Snapshot oldestSnapshot(Table table) {
+  public static Snapshot oldestSnapshot(Table table, long timestampMillis) {

Review comment:
       To simplify the work here, I updated how `SnapshotUtil` works in #3259. 
That adds a way to create an `Iterable<Snapshot>` of the ancestors given some 
starting snapshot, `SnapshotUtil.ancestorsOf`. That should make implementing 
`oldestAncestorAfter` cleaner:
   
   ```java
     /**
      * Traverses the history of the table's current snapshot and finds the 
first snapshot after the given timestamp.
      *
      * @param table a table
      * @param timestampMillis a timestamp in milliseconds
      * @return the first snapshot after the given timestamp, or null if the 
current snapshot is older than the timestamp
      * @throws IllegalStateException if the first ancestor after the given 
time can't be determined
      */
     public static Snapshot oldestAncestorAfter(Table table, long 
timestampMillis) {
       if (table.currentSnapshot() == null) {
         // there are no snapshots or ancestors
         return null;
       }
   
       Snapshot lastSnapshot = null;
       for (Snapshot snapshot : currentAncestors(table)) {
         if (snapshot.timestampMillis() <= timestampMillis) {
           return lastSnapshot;
         }
   
         lastSnapshot = snapshot;
       }
   
       if (lastSnapshot != null && lastSnapshot.parentId() == null) {
         // this is the first snapshot in the table, return it
         return lastSnapshot;
       }
   
       throw new IllegalStateException(
           "Cannot find snapshot older than " + 
DateTimeUtil.formatTimestampMillis(timestampMillis));
     }
   ```




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