rdblue commented on a change in pull request #2660:
URL: https://github.com/apache/iceberg/pull/2660#discussion_r655776796
##########
File path: core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java
##########
@@ -107,4 +121,26 @@ public static boolean ancestorOf(Table table, long
snapshotId, long ancestorSnap
return newFiles;
}
+
+ /**
+ * Traverses the history of the table's current snapshot and finds the
snapshot with the given snapshot id as its
+ * parent.
+ * @return null if the passed in snapshot is not present in the table, else
the snapshot for which the given snapshot
+ * is the parent
+ * @throws IllegalArgumentException when the given SnapshotId is not found
in the table
+ * @throws IllegalStateException when the given snapshot ID is not an
ancestor of the current table state
+ */
+ public static Snapshot snapshotAfter(Table table, long snapshotId) {
+ Snapshot previousSnapshot = table.snapshot(snapshotId);
Review comment:
Actually, I think it may be a good idea to change the loop to exit
early. That would be a bit cleaner. And there's no need to keep the parent
around at all, or to check that it is non-null every time through the loop.
```
Preconditions.checkArgument(table.snapshot(snapshotId) != null, ...);
Snapshot current = table.currentSnapshot();
while (current != null) {
if (current.parentId() == snapshotId) {
return current;
}
current = table.snapshot(current.parentId());
}
throw new IllegalStateException(...);
```
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]