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


##########
core/src/main/java/org/apache/iceberg/TrackingStruct.java:
##########
@@ -268,67 +292,92 @@ public String toString() {
   }
 
   static class Builder {
-    private EntryStatus status = null;
-    private Long snapshotId = null;
-    private Long dataSequenceNumber = null;
-    private Long fileSequenceNumber = null;
-    private Long dvSnapshotId = null;
-    private Long firstRowId = null;
-    private byte[] deletedPositions = null;
-    private byte[] replacedPositions = null;
-
-    Builder status(EntryStatus entryStatus) {
-      this.status = entryStatus;
-      return this;
+    private final EntryStatus status;
+    private final Long snapshotId;
+    private final Long dataSequenceNumber;
+    private final Long fileSequenceNumber;
+    private final Long firstRowId;
+    private Long dvSnapshotId;
+    private byte[] deletedPositions;
+    private byte[] replacedPositions;
+
+    private Builder(long snapshotId) {
+      this.status = EntryStatus.ADDED;
+      this.snapshotId = snapshotId;
+      this.dataSequenceNumber = null;
+      this.fileSequenceNumber = null;
+      this.firstRowId = null;
+      this.deletedPositions = null;
+      this.replacedPositions = null;
     }
 
-    Builder snapshotId(Long id) {
-      this.snapshotId = id;
-      return this;
+    private Builder(Tracking source) {
+      this(EntryStatus.EXISTING, source, source.snapshotId());
     }
 
-    Builder dataSequenceNumber(Long sequenceNumber) {
-      this.dataSequenceNumber = sequenceNumber;
-      return this;
+    private Builder(EntryStatus status, Tracking source, Long snapshotId) {
+      Preconditions.checkArgument(
+          source.dataSequenceNumber() != null,
+          "Invalid tracking source: data sequence number is null");
+      Preconditions.checkArgument(
+          source.fileSequenceNumber() != null,
+          "Invalid tracking source: file sequence number is null");
+      checkStatus(source.status(), status);
+      this.status = status;
+      this.snapshotId = snapshotId;
+      this.dataSequenceNumber = source.dataSequenceNumber();
+      this.fileSequenceNumber = source.fileSequenceNumber();
+      this.firstRowId = source.firstRowId();
+      this.dvSnapshotId = source.dvSnapshotId();
+      this.deletedPositions = null;
+      this.replacedPositions = null;
     }
 
-    Builder fileSequenceNumber(Long sequenceNumber) {
-      this.fileSequenceNumber = sequenceNumber;
-      return this;
+    // TODO: extend allowed transitions once MODIFIED status is added.
+    private static void checkStatus(EntryStatus from, EntryStatus to) {
+      Preconditions.checkArgument(from != null, "Invalid tracking source: 
status is null");
+      Preconditions.checkArgument(
+          from == EntryStatus.ADDED || from == EntryStatus.EXISTING,
+          "Cannot transition from %s status",
+          from);
+      Preconditions.checkArgument(
+          to == EntryStatus.EXISTING || to == EntryStatus.DELETED || to == 
EntryStatus.REPLACED,
+          "Cannot transition to %s status",
+          to);
+      Preconditions.checkArgument(from != to, "Invalid status transition: %s 
-> %s", from, to);
     }
 
-    Builder dvSnapshotId(Long id) {
+    Builder dvSnapshotId(long id) {
+      Preconditions.checkState(
+          status != EntryStatus.DELETED, "Cannot set dv snapshot ID on DELETED 
entry");

Review Comment:
   This is also invalid for an ADDED entry unless the snapshot ID here is equal 
to the entry's snapshot ID, right?



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