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


##########
core/src/main/java/org/apache/iceberg/TrackedFileBuilder.java:
##########
@@ -0,0 +1,364 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+class TrackedFileBuilder {
+  private final long snapshotId;
+  private final FileContent contentType;
+
+  // Required fields
+  private Integer writerFormatVersion = null;
+  private String location = null;
+  private FileFormat fileFormat = null;
+  private Long recordCount = null;
+  private Long fileSizeInBytes = null;
+  private PartitionData partitionData = null;
+
+  // optional fields
+  private Integer specId = null;
+  private ContentStats contentStats = null;
+  private Integer sortOrderId = null;
+  private DeletionVector deletionVector = null;
+  private ManifestInfo manifestInfo = null;
+  private ByteBuffer keyMetadata = null;
+  private List<Long> splitOffsets = null;
+  private List<Integer> equalityIds = null;
+
+  // tracking-related fields
+  private Tracking sourceTracking = null;
+  private boolean dvUpdated = false;
+  private ByteBuffer deletedPositions = null;
+  private ByteBuffer replacedPositions = null;
+
+  /**
+   * Creates a builder for a newly added data file entry.
+   *
+   * @param newSnapshotId the snapshot ID in which the new tracked file will 
be committed
+   */
+  static TrackedFileBuilder data(long newSnapshotId) {
+    return new TrackedFileBuilder(FileContent.DATA, newSnapshotId);
+  }
+
+  /**
+   * Creates a builder for a newly added equality delete file entry.
+   *
+   * @param newSnapshotId the snapshot ID in which the new tracked file will 
be committed
+   */
+  static TrackedFileBuilder equalityDelete(long newSnapshotId) {
+    return new TrackedFileBuilder(FileContent.EQUALITY_DELETES, newSnapshotId);
+  }
+
+  /**
+   * Creates a builder for a newly added data manifest entry.
+   *
+   * @param newSnapshotId the snapshot ID in which the new tracked file will 
be committed
+   */
+  static TrackedFileBuilder dataManifest(long newSnapshotId) {
+    return new TrackedFileBuilder(FileContent.DATA_MANIFEST, newSnapshotId);
+  }
+
+  /**
+   * Creates a builder for a newly added delete manifest entry.
+   *
+   * @param newSnapshotId the snapshot ID in which the new tracked file will 
be committed
+   */
+  static TrackedFileBuilder deleteManifest(long newSnapshotId) {
+    return new TrackedFileBuilder(FileContent.DELETE_MANIFEST, newSnapshotId);
+  }
+
+  /**
+   * Creates a builder for a tracked file derived from {@code source}.
+   *
+   * @param source source tracked file to copy fields from
+   * @param newSnapshotId the snapshot ID in which the new tracked file will 
be committed
+   */
+  static TrackedFileBuilder from(TrackedFile source, long newSnapshotId) {
+    Preconditions.checkArgument(source != null, "Invalid source: null");
+    return new TrackedFileBuilder(source, newSnapshotId);
+  }
+
+  /**
+   * Returns a DELETED tracked file derived from {@code source}.
+   *
+   * @param source source tracked file
+   * @param newSnapshotId the snapshot ID in which the new tracked file will 
be committed
+   */
+  static TrackedFile deleted(TrackedFile source, long newSnapshotId) {
+    Preconditions.checkArgument(source != null, "Invalid source: null");
+    return terminal(source, TrackingBuilder.deleted(source.tracking(), 
newSnapshotId));
+  }
+
+  /**
+   * Returns a REPLACED tracked file derived from {@code source}.
+   *
+   * <p>Manifest entries cannot transition to REPLACED.
+   *
+   * @param source source tracked file
+   * @param newSnapshotId the snapshot ID in which the new tracked file will 
be committed
+   */
+  static TrackedFile replaced(TrackedFile source, long newSnapshotId) {
+    Preconditions.checkArgument(source != null, "Invalid source: null");
+    Preconditions.checkArgument(
+        !isLeafManifest(source.contentType()),
+        "Manifest entries cannot transition to REPLACED, but entry type is: 
%s",

Review Comment:
   This is less direct than we typically prefer, but is not bad. This states a 
general rule and then says that it applies. We would normally say that at once: 
`"Cannot transition %s to REPLACED"`.



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