@@ -146,7 +146,7 @@ public void testInsertsUpsertsAndDeletes(boolean isPartitioned) {
146
146
List <TableChange > allTableChanges = new ArrayList <>();
147
147
148
148
testIcebergTable .insertRows (50 );
149
- Long timestamp1 = testIcebergTable .getLastCommitTimestamp ();
149
+ long timestamp1 = testIcebergTable .getLastCommitTimestamp ();
150
150
allActiveFiles .add (testIcebergTable .getAllActiveFiles ());
151
151
152
152
List <Record > records1 = testIcebergTable .insertRows (50 );
@@ -204,7 +204,7 @@ public void testDropPartition() {
204
204
List <TableChange > allTableChanges = new ArrayList <>();
205
205
206
206
List <Record > records1 = testIcebergTable .insertRows (50 );
207
- Long timestamp1 = testIcebergTable .getLastCommitTimestamp ();
207
+ long timestamp1 = testIcebergTable .getLastCommitTimestamp ();
208
208
allActiveFiles .add (testIcebergTable .getAllActiveFiles ());
209
209
210
210
List <Record > records2 = testIcebergTable .insertRows (50 );
@@ -264,7 +264,7 @@ public void testDeleteAllRecordsInPartition() {
264
264
List <TableChange > allTableChanges = new ArrayList <>();
265
265
266
266
List <Record > records1 = testIcebergTable .insertRows (50 );
267
- Long timestamp1 = testIcebergTable .getLastCommitTimestamp ();
267
+ long timestamp1 = testIcebergTable .getLastCommitTimestamp ();
268
268
allActiveFiles .add (testIcebergTable .getAllActiveFiles ());
269
269
270
270
List <Record > records2 = testIcebergTable .insertRows (50 );
@@ -325,7 +325,7 @@ public void testExpireSnapshots(boolean isPartitioned) throws InterruptedExcepti
325
325
List <TableChange > allTableChanges = new ArrayList <>();
326
326
327
327
List <Record > records1 = testIcebergTable .insertRows (50 );
328
- Long timestamp1 = testIcebergTable .getLastCommitTimestamp ();
328
+ long timestamp1 = testIcebergTable .getLastCommitTimestamp ();
329
329
330
330
testIcebergTable .upsertRows (records1 .subList (0 , 20 ));
331
331
allActiveFiles .add (testIcebergTable .getAllActiveFiles ());
@@ -383,8 +383,8 @@ public void testForIncrementalSyncSafetyCheck(boolean shouldExpireSnapshots) {
383
383
TestIcebergTable .forStandardSchemaAndPartitioning (
384
384
tableName , "level" , tempDir , hadoopConf )) {
385
385
// Insert 50 rows to INFO partition.
386
- List <Record > commit1Rows = testIcebergTable .insertRecordsForPartition (50 , "INFO" );
387
- Long timestamp1 = testIcebergTable .getLastCommitTimestamp ();
386
+ List <Record > firstCommitRows = testIcebergTable .insertRecordsForPartition (50 , "INFO" );
387
+ long timestampAfterFirstCommit = testIcebergTable .getLastCommitTimestamp ();
388
388
SourceTable tableConfig =
389
389
SourceTable .builder ()
390
390
.name (testIcebergTable .getTableName ())
@@ -393,23 +393,42 @@ public void testForIncrementalSyncSafetyCheck(boolean shouldExpireSnapshots) {
393
393
.build ();
394
394
395
395
// Upsert all rows inserted before, so all files are replaced.
396
- testIcebergTable .upsertRows (commit1Rows .subList (0 , 50 ));
397
- long snapshotIdAfterCommit2 = testIcebergTable .getLatestSnapshot ().snapshotId ();
396
+ testIcebergTable .upsertRows (firstCommitRows .subList (0 , 50 ));
397
+ long timestampAfterSecondCommit = testIcebergTable .getLastCommitTimestamp ();
398
+ long snapshotIdAfterSecondCommit = testIcebergTable .getLatestSnapshot ().snapshotId ();
398
399
399
400
// Insert 50 rows to different (ERROR) partition.
400
401
testIcebergTable .insertRecordsForPartition (50 , "ERROR" );
402
+ long timestampAfterThirdCommit = testIcebergTable .getLastCommitTimestamp ();
401
403
402
404
if (shouldExpireSnapshots ) {
403
405
// Expire snapshotAfterCommit2.
404
- testIcebergTable .expireSnapshot (snapshotIdAfterCommit2 );
406
+ testIcebergTable .expireSnapshot (snapshotIdAfterSecondCommit );
405
407
}
406
408
IcebergConversionSource conversionSource =
407
409
sourceProvider .getConversionSourceInstance (tableConfig );
408
410
if (shouldExpireSnapshots ) {
409
- assertFalse (conversionSource .isIncrementalSyncSafeFrom (Instant .ofEpochMilli (timestamp1 )));
411
+ // Since the second snapshot is expired, we cannot safely perform incremental sync from the
412
+ // first two commits
413
+ assertFalse (
414
+ conversionSource .isIncrementalSyncSafeFrom (
415
+ Instant .ofEpochMilli (timestampAfterFirstCommit )));
416
+ assertFalse (
417
+ conversionSource .isIncrementalSyncSafeFrom (
418
+ Instant .ofEpochMilli (timestampAfterSecondCommit )));
410
419
} else {
411
- assertTrue (conversionSource .isIncrementalSyncSafeFrom (Instant .ofEpochMilli (timestamp1 )));
420
+ // The full history is still present so incremental sync is safe from any of these commits
421
+ assertTrue (
422
+ conversionSource .isIncrementalSyncSafeFrom (
423
+ Instant .ofEpochMilli (timestampAfterFirstCommit )));
424
+ assertTrue (
425
+ conversionSource .isIncrementalSyncSafeFrom (
426
+ Instant .ofEpochMilli (timestampAfterSecondCommit )));
412
427
}
428
+ // Table always has the last commit so incremental sync is safe
429
+ assertTrue (
430
+ conversionSource .isIncrementalSyncSafeFrom (
431
+ Instant .ofEpochMilli (timestampAfterThirdCommit )));
413
432
// Table doesn't have instant of this older commit, hence it is not safe.
414
433
Instant instantAsOfHourAgo = Instant .now ().minus (1 , ChronoUnit .HOURS );
415
434
assertFalse (conversionSource .isIncrementalSyncSafeFrom (instantAsOfHourAgo ));
0 commit comments