stevenzwu commented on code in PR #6401:
URL: https://github.com/apache/iceberg/pull/6401#discussion_r1066580668


##########
flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java:
##########
@@ -213,17 +213,12 @@ static Optional<Snapshot> startSnapshot(Table table, 
ScanContext scanContext) {
             "Start snapshot id not found in history: " + 
scanContext.startSnapshotId());
         return Optional.of(matchedSnapshotById);
       case INCREMENTAL_FROM_SNAPSHOT_TIMESTAMP:
-        long snapshotIdAsOfTime =
-            SnapshotUtil.snapshotIdAsOfTime(table, 
scanContext.startSnapshotTimestamp());
-        Snapshot matchedSnapshotByTimestamp = 
table.snapshot(snapshotIdAsOfTime);
-        if (matchedSnapshotByTimestamp.timestampMillis() == 
scanContext.startSnapshotTimestamp()) {
-          return Optional.of(matchedSnapshotByTimestamp);
-        } else {
-          // if the snapshotIdAsOfTime has the timestamp value smaller than the
-          // scanContext.startSnapshotTimestamp(),
-          // return the child snapshot whose timestamp value is larger
-          return Optional.of(SnapshotUtil.snapshotAfter(table, 
snapshotIdAsOfTime));
-        }
+        Snapshot matchedSnapshotByTimestamp =
+            SnapshotUtil.oldestAncestorAfter(table, 
scanContext.startSnapshotTimestamp());
+        Preconditions.checkArgument(
+            matchedSnapshotByTimestamp != null,
+            "Cannot find a snapshot after: " + 
scanContext.startSnapshotTimestamp());
+        return Optional.of(matchedSnapshotByTimestamp);

Review Comment:
   This fix seems correct. 
   
   Old logic actually has a little problem, because it checks 
`List<HistoryEntry>` (not the ancestor history of the current table 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.

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