timothyw553 commented on code in PR #19099:
URL: https://github.com/apache/iceberg/pull/19099#discussion_r4708117019


##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java:
##########
@@ -220,13 +221,23 @@ private ContinuousEnumerationResult 
discoverInitialSplits() {
    */
   @VisibleForTesting
   static Optional<Snapshot> startSnapshot(Table table, ScanContext 
scanContext) {
+    String branch = scanContext.branch();
+    if (branch != null
+        && !SnapshotRef.MAIN_BRANCH.equals(branch)
+        && table.snapshot(branch) == null) {
+      branch = null;
+    }
+
+    Snapshot headSnapshot = SnapshotUtil.latestSnapshot(table, branch);
+
     switch (scanContext.streamingStartingStrategy()) {
       case TABLE_SCAN_THEN_INCREMENTAL:
       case INCREMENTAL_FROM_LATEST_SNAPSHOT:
       case INCREMENTAL_FROM_LATEST_SNAPSHOT_EXCLUSIVE:
-        return Optional.ofNullable(table.currentSnapshot());
+        return Optional.ofNullable(headSnapshot);

Review Comment:
   this change is shared by `TABLE_SCAN_THEN_INCREMENTAL` and 
`INCREMENTAL_FROM_LATEST_SNAPSHOT_EXCLUSIVE`, while the new test only covers 
`INCREMENTAL_FROM_LATEST_SNAPSHOT` and `testReadingFromBranch` passes even on 
the old planner. could we add separate tests for those two strategies (checking 
that initial scan excludes main-only files and exclusive skips existing branch 
files)?



##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/source/enumerator/ContinuousSplitPlannerImpl.java:
##########
@@ -220,13 +221,23 @@ private ContinuousEnumerationResult 
discoverInitialSplits() {
    */
   @VisibleForTesting
   static Optional<Snapshot> startSnapshot(Table table, ScanContext 
scanContext) {
+    String branch = scanContext.branch();
+    if (branch != null
+        && !SnapshotRef.MAIN_BRANCH.equals(branch)
+        && table.snapshot(branch) == null) {
+      branch = null;

Review Comment:
   why are we falling back to `main` when `branch` doesn't exist? to my 
understanding later scans still use the original branch name and see no 
snapshot, which reads `main`'s files first and then fails with `Invalid last 
enumerated position for an empty table: not null` when `main` has 2+ snapshots. 
should we throw here instead and add a test for a missing branch?
   
   ```diff
    if (branch != null
        && !SnapshotRef.MAIN_BRANCH.equals(branch)
        && table.snapshot(branch) == null) {
   -  branch = null;
   +  throw new IllegalArgumentException("Cannot find branch: " + branch);
    }
   ```



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