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


##########
flink/v2.3/flink/src/test/java/org/apache/iceberg/flink/source/enumerator/TestContinuousSplitPlannerImpl.java:
##########
@@ -655,6 +658,120 @@ public void testTableScanSingleStat() throws Exception {
     }
   }
 
+  @Test
+  public void testIncrementalFromLatestSnapshotStartsFromBranchHead() throws 
Exception {
+    DataFile branchFile = appendToBranch();
+
+    ScanContext scanContext =
+        ScanContext.builder()
+            
.startingStrategy(StreamingStartingStrategy.INCREMENTAL_FROM_LATEST_SNAPSHOT)
+            .useBranch(BRANCH)
+            .build();
+    ContinuousSplitPlannerImpl splitPlanner =
+        new ContinuousSplitPlannerImpl(TABLE_RESOURCE.tableLoader().clone(), 
scanContext, null);
+
+    ContinuousEnumerationResult initialResult = splitPlanner.planSplits(null);
+    assertThat(splitPlanner.planSplits(initialResult.toPosition()).splits())
+        .flatExtracting(split -> split.task().files())
+        .extracting(task -> task.file().location())
+        .containsExactly(branchFile.location());
+  }
+
+  @Test
+  public void testIncrementalFromSnapshotTimestampUsesBranchHistory() throws 
Exception {
+    DataFile branchFile = appendToBranch();
+
+    ScanContext scanContext =
+        ScanContext.builder()
+            
.startingStrategy(StreamingStartingStrategy.INCREMENTAL_FROM_SNAPSHOT_TIMESTAMP)
+            
.startSnapshotTimestamp(TABLE_RESOURCE.table().snapshot(BRANCH).timestampMillis())
+            .useBranch(BRANCH)
+            .build();
+    ContinuousSplitPlannerImpl splitPlanner =
+        new ContinuousSplitPlannerImpl(TABLE_RESOURCE.tableLoader().clone(), 
scanContext, null);
+
+    ContinuousEnumerationResult initialResult = splitPlanner.planSplits(null);
+    IcebergSourceSplit split =
+        
Iterables.getOnlyElement(splitPlanner.planSplits(initialResult.toPosition()).splits());
+    assertThat(split.task().files())
+        .singleElement()
+        .satisfies(task -> 
assertThat(task.file().location()).isEqualTo(branchFile.location()));
+  }
+
+  @Test
+  public void 
testIncrementalFromEarliestSnapshotUsesBranchHistoryAfterMainExpiration()
+      throws Exception {
+    Table table = TABLE_RESOURCE.table();
+    DataFile baseFile =
+        dataAppender.writeFile(null, 
RandomGenericData.generate(TestFixtures.SCHEMA, 2, 0L));
+    dataAppender.appendToTable(baseFile);
+    table.manageSnapshots().createBranch(BRANCH, 
table.currentSnapshot().snapshotId()).commit();
+    dataAppender.appendToTable(RandomGenericData.generate(TestFixtures.SCHEMA, 
2, 1L));
+    long expiredMainSnapshotId = table.currentSnapshot().snapshotId();
+    dataAppender.appendToTable(RandomGenericData.generate(TestFixtures.SCHEMA, 
2, 2L));
+    DataFile branchFile =
+        dataAppender.writeFile(null, 
RandomGenericData.generate(TestFixtures.SCHEMA, 2, 3L));
+    table.newAppend().appendFile(branchFile).toBranch(BRANCH).commit();
+    table.expireSnapshots().expireSnapshotId(expiredMainSnapshotId).commit();
+
+    ScanContext scanContext =
+        ScanContext.builder()
+            
.startingStrategy(StreamingStartingStrategy.INCREMENTAL_FROM_EARLIEST_SNAPSHOT)
+            .useBranch(BRANCH)
+            .build();
+    ContinuousSplitPlannerImpl splitPlanner =
+        new ContinuousSplitPlannerImpl(TABLE_RESOURCE.tableLoader().clone(), 
scanContext, null);
+
+    ContinuousEnumerationResult initialResult = splitPlanner.planSplits(null);
+    assertThat(splitPlanner.planSplits(initialResult.toPosition()).splits())
+        .flatExtracting(split -> split.task().files())
+        .extracting(task -> task.file().location())
+        .containsExactlyInAnyOrder(baseFile.location(), branchFile.location());
+  }
+
+  @Test
+  public void testTableScanThenIncrementalExcludesMainOnlyFiles() throws 
Exception {
+    Table table = TABLE_RESOURCE.table();
+    DataFile baseFile =
+        dataAppender.writeFile(null, 
RandomGenericData.generate(TestFixtures.SCHEMA, 2, 0L));
+    dataAppender.appendToTable(baseFile);
+    table.manageSnapshots().createBranch(BRANCH, 
table.currentSnapshot().snapshotId()).commit();
+    dataAppender.appendToTable(RandomGenericData.generate(TestFixtures.SCHEMA, 
2, 1L));
+    DataFile branchFile =
+        dataAppender.writeFile(null, 
RandomGenericData.generate(TestFixtures.SCHEMA, 2, 2L));
+    table.newAppend().appendFile(branchFile).toBranch(BRANCH).commit();
+
+    ScanContext scanContext =
+        ScanContext.builder()
+            
.startingStrategy(StreamingStartingStrategy.TABLE_SCAN_THEN_INCREMENTAL)
+            .useBranch(BRANCH)
+            .build();
+    ContinuousSplitPlannerImpl splitPlanner =
+        new ContinuousSplitPlannerImpl(TABLE_RESOURCE.tableLoader().clone(), 
scanContext, null);
+
+    assertThat(splitPlanner.planSplits(null).splits())
+        .flatExtracting(split -> split.task().files())
+        .extracting(task -> task.file().location())
+        .containsExactlyInAnyOrder(baseFile.location(), branchFile.location());
+  }
+
+  @Test
+  public void 
testIncrementalFromLatestSnapshotExclusiveSkipsExistingBranchFiles()
+      throws Exception {
+    appendToBranch();
+
+    ScanContext scanContext =
+        ScanContext.builder()
+            
.startingStrategy(StreamingStartingStrategy.INCREMENTAL_FROM_LATEST_SNAPSHOT_EXCLUSIVE)
+            .useBranch(BRANCH)
+            .build();
+    ContinuousSplitPlannerImpl splitPlanner =
+        new ContinuousSplitPlannerImpl(TABLE_RESOURCE.tableLoader().clone(), 
scanContext, null);
+
+    ContinuousEnumerationResult initialResult = splitPlanner.planSplits(null);
+    
assertThat(splitPlanner.planSplits(initialResult.toPosition()).splits()).isEmpty();

Review Comment:
   Good point, updated.



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