rdblue commented on a change in pull request #2660:
URL: https://github.com/apache/iceberg/pull/2660#discussion_r655774796
##########
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);
+ Preconditions.checkArgument(previousSnapshot != null,
+ "Invalid snapshotId: %s, snapshot not found in the table.",
snapshotId);
+
+ Snapshot current = table.currentSnapshot();
+ while (previousSnapshot != null && current != null &&
previousSnapshot.snapshotId() != current.parentId()) {
+ current = table.snapshot(current.parentId());
+ }
+
+ Preconditions.checkState(current != null, "Cannot find next snapshot: as
Snapshot %s expired", snapshotId);
Review comment:
I don't think that this error message is correct. The problem is that
traversing the current snapshot's history didn't find the parent snapshot.
Since the parent is defined (we know this from the check above) we know that
the parent is actually not an ancestor of the current table state. That's a
more descriptive error message: `"Cannot find snapshot after %s: not an
ancestor of the current snapshot"`
--
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]