rdblue commented on a change in pull request #3039:
URL: https://github.com/apache/iceberg/pull/3039#discussion_r753832515
##########
File path: core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java
##########
@@ -101,6 +101,41 @@ 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.
+ * @return null if there is no current snapshot in the table,
+ * else the oldest ancestor snapshot after or equal to the timestamp in
milliseconds.
+ */
+ public static Snapshot oldestAncestorAfter(Table table, Long
timestampMillis) {
+ Snapshot current = table.currentSnapshot();
+ long timestamp = timestampMillis == null ? -1L : timestampMillis;
+ if (current == null || current.timestampMillis() < timestamp) {
+ return null;
+ }
+
+ for (Snapshot snapshot : currentAncestors(table)) {
+ if (snapshot.timestampMillis() < timestamp) {
+ break;
+ }
+
+ current = snapshot;
+ }
+
+ return current;
Review comment:
I don't think this logic is correct. In the version that I wrote, the
method will throw an `IllegalStateException` if it cannot determine whether the
ancestor was actually the first snapshot after the given timestamp. It is fine
if the behavior you want is to ignore that case in practice, but the utility
methods in `SnapshotUtil` should be more careful. What you should do instead is
call `oldestAncestor` if this fails to find one and you want to default to the
oldest ancestor.
--
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]