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


##########
core/src/main/java/org/apache/iceberg/TrackingStruct.java:
##########
@@ -132,6 +151,38 @@ void inherit(long manifestSnapshotId, long 
manifestSeqNumber) {
     }
   }
 
+  /**
+   * Assign the first row ID to the given next row ID if it is unassigned.
+   *
+   * <p>If the {@code nextRowId} is null, the first row ID will also be set to 
null. This is used
+   * when reading snapshots from older format versions that do not have 
assigned row IDs.
+   *
+   * @param nextRowId the next row ID to assign, or null when reading v2 or 
earlier snapshots
+   * @return true if the first row ID is assigned a non-null value
+   */
+  boolean assignFirstRowId(Long nextRowId) {
+    if (null == nextRowId) {
+      // null manifest first row ID from pre-v3 upgrade path
+      // defensively set the first row ID for every entry to be null
+      this.firstRowId = null;
+      return false;
+    }
+
+    boolean isAdded = status == EntryStatus.ADDED;
+    // EXISTING will assign to handle existing files upgraded from pre-v3
+    boolean isExisting = status == EntryStatus.EXISTING;
+    // MODIFIED will assign to handle existing files upgraded from pre-v3 AND 
modified in the first
+    // v4 commit when IDs are assigned
+    boolean isModified = status == EntryStatus.MODIFIED;

Review Comment:
   The replaced logic was `status != DELETED` but this needs to handle both 
`MODIFIED` and `REPLACED`. I think it's clear that `REPLACED` should behave 
like `DELETED` and should not be assigned a first row ID.
   
   `MODIFIED` behaves like `EXISTING`. There is a narrow case that requires 
this: when a v2 table is upgraded to v3 and then v4 without assignment, then 
the first commit modifies and existing file. In this case, the file will have 
no first row ID, but will have `MODIFIED` status. Otherwise, a file must 
transition through `EXISTING` (upgraded from pre-v3) or `ADDED` (upgraded or 
committed in a v3 or newer 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