rdblue commented on code in PR #4886:
URL: https://github.com/apache/iceberg/pull/4886#discussion_r884322531


##########
core/src/main/java/org/apache/iceberg/BaseIncrementalAppendScan.java:
##########
@@ -71,46 +71,41 @@ public IncrementalAppendScan toSnapshot(long toSnapshotId) {
 
   @Override
   public CloseableIterable<FileScanTask> planFiles() {
-    long toSnapshotIdInclusive;
-    if (context().toSnapshotId() != null) {
-      toSnapshotIdInclusive = context().toSnapshotId();
-    } else if (table().currentSnapshot() != null) {
-      toSnapshotIdInclusive = table().currentSnapshot().snapshotId();
-    } else if (context().fromSnapshotId() != null) {
-      throw new IllegalArgumentException(
-          "Invalid config: end snapshot is not set, start snapshot is set, and 
table has no current snapshot");
-    } else {
-      // It is an empty table (no current snapshot). Both from and to 
snapshots aren't set either.
-      // In this case, listener notification is also skipped
+    Long fromSnapshotId = context().fromSnapshotId();
+    Long toSnapshotId = context().toSnapshotId();
+    if (fromSnapshotId == null && toSnapshotId == null && 
table().currentSnapshot() == null) {
+      // If it is an empty table (no current snapshot) and both from and to 
snapshots aren't set either,
+      // simply return an empty iterable. In this case, listener notification 
is also skipped.
       return CloseableIterable.empty();
     }
 
+    long toSnapshotIdInclusive = toSnapshotIdExclusive();
     // fromSnapshotIdExclusive can be null. appendsBetween handles null 
fromSnapshotIdExclusive properly
     // by finding the oldest ancestor of end snapshot.
-    Long fromSnapshotIdExclusive = context().fromSnapshotId();
-    if (context().fromSnapshotId() != null) {
+    Long fromSnapshotIdExclusive = fromSnapshotId;

Review Comment:
   If `fromSnapshotId` may be inclusive, then it should never be assigned to 
`fromSnapshotIdExclusive` without first checking. Otherwise, there is 
temporarily a value for `fromSnapshotIdExclusive` that is incorrect. If you 
have a guarantee in the variable name, you should never violate that guarantee 
because someone might not know about it later.



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