anoopj commented on code in PR #15049:
URL: https://github.com/apache/iceberg/pull/15049#discussion_r2692590961


##########
core/src/main/java/org/apache/iceberg/TrackedFile.java:
##########
@@ -0,0 +1,282 @@
+/*
+ * 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 java.util.Set;
+import org.apache.iceberg.types.Types;
+
+/**
+ * Represents a V4 content entry in a manifest file.
+ *
+ * <p>TrackedFile is the V4 equivalent of ContentFile. It provides a unified 
representation for all
+ * entry types in a V4 manifest: data files, delete files, manifests, and 
deletion vectors.
+ */
+interface TrackedFile {
+  // Field IDs from V4 specification
+  Types.NestedField TRACKING_INFO =
+      Types.NestedField.required(
+          147, "tracking_info", TrackingInfo.schema(), "Tracking information 
for this entry");
+  Types.NestedField CONTENT_TYPE =
+      Types.NestedField.required(
+          134,
+          "content_type",
+          Types.IntegerType.get(),
+          "Type of content: 0=DATA, 1=POSITION_DELETES, 2=EQUALITY_DELETES, 
3=DATA_MANIFEST, 4=DELETE_MANIFEST");
+  Types.NestedField LOCATION =
+      Types.NestedField.required(100, "location", Types.StringType.get(), 
"Location of the file");
+  Types.NestedField FILE_FORMAT =
+      Types.NestedField.required(
+          101,
+          "file_format",
+          Types.StringType.get(),
+          "String file format name: avro, orc, parquet, or puffin");
+  Types.NestedField PARTITION_SPEC_ID =
+      Types.NestedField.required(
+          149,
+          "partition_spec_id",
+          Types.IntegerType.get(),
+          "ID of partition spec used to write manifest or data/delete files");
+  Types.NestedField SORT_ORDER_ID =
+      Types.NestedField.optional(
+          140,
+          "sort_order_id",
+          Types.IntegerType.get(),
+          "ID representing sort order for this file. Can only be set if 
content_type is 0");
+  Types.NestedField RECORD_COUNT =
+      Types.NestedField.required(
+          103,
+          "record_count",
+          Types.LongType.get(),
+          "Number of records in this file, or the cardinality of a deletion 
vector");
+  Types.NestedField FILE_SIZE_IN_BYTES =
+      Types.NestedField.optional(
+          104, "file_size_in_bytes", Types.LongType.get(), "Total file size in 
bytes.");
+  Types.NestedField CONTENT_STATS =
+      Types.NestedField.optional(
+          146,
+          "content_stats",
+          Types.StructType.of(), // TODO: Define ContentStats structure per V4 
proposal
+          "Content statistics for this entry");
+  Types.NestedField KEY_METADATA =
+      Types.NestedField.optional(
+          131,
+          "key_metadata",
+          Types.BinaryType.get(),
+          "Implementation-specific key metadata for encryption");
+  Types.NestedField SPLIT_OFFSETS =
+      Types.NestedField.optional(
+          132,
+          "split_offsets",
+          Types.ListType.ofRequired(133, Types.LongType.get()),
+          "Split offsets for the data file. Must be sorted ascending");
+  Types.NestedField CONTENT_INFO =
+      Types.NestedField.optional(
+          148,
+          "content_info",
+          ContentInfo.schema(),
+          "Content info. Required when content_type is POSITION_DELETES, must 
be null otherwise");
+  Types.NestedField EQUALITY_IDS =
+      Types.NestedField.optional(
+          135,
+          "equality_ids",
+          Types.ListType.ofRequired(136, Types.IntegerType.get()),
+          "Field ids used to determine row equality in equality delete files. 
Required when content=2");
+  Types.NestedField REFERENCED_FILE =
+      Types.NestedField.optional(
+          143,
+          "referenced_file",
+          Types.StringType.get(),
+          "Location of data file that a DV references if content_type is 
POSITION_DELETES. "
+              + "Location of affiliated data manifest if content_type is 
DELETE_MANIFEST, or null if unaffiliated");
+  Types.NestedField MANIFEST_STATS =
+      Types.NestedField.optional(
+          150,
+          "manifest_stats",
+          ManifestStats.schema(),
+          "Manifest statistics. Required for DATA_MANIFEST and 
DELETE_MANIFEST");
+  Types.NestedField MANIFEST_DV =
+      Types.NestedField.optional(
+          151,
+          "manifest_dv",
+          Types.BinaryType.get(),
+          "Serialized deletion vector marking deleted entry positions in the 
referenced manifest. "
+              + "Optional for DATA_MANIFEST and DELETE_MANIFEST, must be null 
for other content types");
+
+  /**
+   * Returns the path of the manifest which this file is referenced in or null 
if it was not read
+   * from a manifest.
+   */
+  String manifestLocation();
+
+  /**
+   * Returns the tracking information for this entry.
+   *
+   * <p>Contains status, snapshot ID, sequence numbers, and first-row-id. 
Optional - may be null if
+   * tracking info is inherited.
+   */
+  TrackingInfo trackingInfo();
+
+  /**
+   * Returns the type of content stored by this entry.
+   *
+   * <p>One of: DATA, POSITION_DELETES, EQUALITY_DELETES, DATA_MANIFEST, or 
DELETE_MANIFEST.
+   */
+  FileContent contentType();
+
+  /** Returns the location of the file. */
+  String location();
+
+  /** Returns the format of the file (avro, orc, parquet, or puffin). */
+  FileFormat fileFormat();
+
+  /**
+   * Returns the content info.
+   *
+   * <p>Must be defined if content_type is POSITION_DELETES, must be null 
otherwise.
+   */
+  ContentInfo contentInfo();
+
+  /** Returns the ID of the partition spec used to write this file or 
manifest. */
+  int partitionSpecId();
+
+  /**
+   * Returns the ID representing sort order for this file.
+   *
+   * <p>Can only be set if content_type is DATA.
+   */
+  Integer sortOrderId();

Review Comment:
   I prefer to keep the nullable `Integer` API because:
   
     - The field is optional in the V4 schema
     - `ContentFile.sortOrderId()` already returns Integer with a default of 
null



##########
core/src/main/java/org/apache/iceberg/TrackedFile.java:
##########
@@ -0,0 +1,282 @@
+/*
+ * 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 java.util.Set;
+import org.apache.iceberg.types.Types;
+
+/**
+ * Represents a V4 content entry in a manifest file.
+ *
+ * <p>TrackedFile is the V4 equivalent of ContentFile. It provides a unified 
representation for all
+ * entry types in a V4 manifest: data files, delete files, manifests, and 
deletion vectors.
+ */
+interface TrackedFile {
+  // Field IDs from V4 specification
+  Types.NestedField TRACKING_INFO =
+      Types.NestedField.required(
+          147, "tracking_info", TrackingInfo.schema(), "Tracking information 
for this entry");
+  Types.NestedField CONTENT_TYPE =
+      Types.NestedField.required(
+          134,
+          "content_type",
+          Types.IntegerType.get(),
+          "Type of content: 0=DATA, 1=POSITION_DELETES, 2=EQUALITY_DELETES, 
3=DATA_MANIFEST, 4=DELETE_MANIFEST");
+  Types.NestedField LOCATION =
+      Types.NestedField.required(100, "location", Types.StringType.get(), 
"Location of the file");
+  Types.NestedField FILE_FORMAT =
+      Types.NestedField.required(
+          101,
+          "file_format",
+          Types.StringType.get(),
+          "String file format name: avro, orc, parquet, or puffin");
+  Types.NestedField PARTITION_SPEC_ID =
+      Types.NestedField.required(
+          149,
+          "partition_spec_id",
+          Types.IntegerType.get(),
+          "ID of partition spec used to write manifest or data/delete files");
+  Types.NestedField SORT_ORDER_ID =
+      Types.NestedField.optional(
+          140,
+          "sort_order_id",
+          Types.IntegerType.get(),
+          "ID representing sort order for this file. Can only be set if 
content_type is 0");
+  Types.NestedField RECORD_COUNT =
+      Types.NestedField.required(
+          103,
+          "record_count",
+          Types.LongType.get(),
+          "Number of records in this file, or the cardinality of a deletion 
vector");
+  Types.NestedField FILE_SIZE_IN_BYTES =
+      Types.NestedField.optional(
+          104, "file_size_in_bytes", Types.LongType.get(), "Total file size in 
bytes.");
+  Types.NestedField CONTENT_STATS =
+      Types.NestedField.optional(
+          146,
+          "content_stats",
+          Types.StructType.of(), // TODO: Define ContentStats structure per V4 
proposal
+          "Content statistics for this entry");
+  Types.NestedField KEY_METADATA =
+      Types.NestedField.optional(
+          131,
+          "key_metadata",
+          Types.BinaryType.get(),
+          "Implementation-specific key metadata for encryption");
+  Types.NestedField SPLIT_OFFSETS =
+      Types.NestedField.optional(
+          132,
+          "split_offsets",
+          Types.ListType.ofRequired(133, Types.LongType.get()),
+          "Split offsets for the data file. Must be sorted ascending");
+  Types.NestedField CONTENT_INFO =
+      Types.NestedField.optional(
+          148,
+          "content_info",
+          ContentInfo.schema(),
+          "Content info. Required when content_type is POSITION_DELETES, must 
be null otherwise");
+  Types.NestedField EQUALITY_IDS =
+      Types.NestedField.optional(
+          135,
+          "equality_ids",
+          Types.ListType.ofRequired(136, Types.IntegerType.get()),
+          "Field ids used to determine row equality in equality delete files. 
Required when content=2");
+  Types.NestedField REFERENCED_FILE =
+      Types.NestedField.optional(
+          143,
+          "referenced_file",
+          Types.StringType.get(),
+          "Location of data file that a DV references if content_type is 
POSITION_DELETES. "
+              + "Location of affiliated data manifest if content_type is 
DELETE_MANIFEST, or null if unaffiliated");
+  Types.NestedField MANIFEST_STATS =
+      Types.NestedField.optional(
+          150,
+          "manifest_stats",
+          ManifestStats.schema(),
+          "Manifest statistics. Required for DATA_MANIFEST and 
DELETE_MANIFEST");
+  Types.NestedField MANIFEST_DV =
+      Types.NestedField.optional(
+          151,
+          "manifest_dv",
+          Types.BinaryType.get(),
+          "Serialized deletion vector marking deleted entry positions in the 
referenced manifest. "
+              + "Optional for DATA_MANIFEST and DELETE_MANIFEST, must be null 
for other content types");
+
+  /**
+   * Returns the path of the manifest which this file is referenced in or null 
if it was not read
+   * from a manifest.
+   */
+  String manifestLocation();
+
+  /**
+   * Returns the tracking information for this entry.
+   *
+   * <p>Contains status, snapshot ID, sequence numbers, and first-row-id. 
Optional - may be null if
+   * tracking info is inherited.
+   */
+  TrackingInfo trackingInfo();
+
+  /**
+   * Returns the type of content stored by this entry.
+   *
+   * <p>One of: DATA, POSITION_DELETES, EQUALITY_DELETES, DATA_MANIFEST, or 
DELETE_MANIFEST.
+   */
+  FileContent contentType();
+
+  /** Returns the location of the file. */
+  String location();
+
+  /** Returns the format of the file (avro, orc, parquet, or puffin). */
+  FileFormat fileFormat();
+
+  /**
+   * Returns the content info.
+   *
+   * <p>Must be defined if content_type is POSITION_DELETES, must be null 
otherwise.
+   */
+  ContentInfo contentInfo();
+
+  /** Returns the ID of the partition spec used to write this file or 
manifest. */
+  int partitionSpecId();
+
+  /**
+   * Returns the ID representing sort order for this file.
+   *
+   * <p>Can only be set if content_type is DATA.
+   */
+  Integer sortOrderId();
+
+  /** Returns the number of records in this file, or the cardinality of a 
deletion vector. */
+  long recordCount();
+
+  /**
+   * Returns the total file size in bytes.
+   *
+   * <p>Must be defined if location is defined.
+   */
+  Long fileSizeInBytes();
+
+  /**
+   * Returns the content stats for this entry.
+   *
+   * <p>TODO: Define ContentStats structure per V4 proposal.
+   */
+  Object contentStats();
+
+  /**
+   * Returns the manifest stats for this entry.
+   *
+   * <p>Must be set if content_type is DATA_MANIFEST or DELETE_MANIFEST, 
otherwise must be null.
+   */
+  ManifestStats manifestStats();
+
+  /**
+   * Returns the manifest deletion vector for this entry.
+   *
+   * <p>When present, this is a serialized deletion vector where each set bit 
position corresponds
+   * to an entry in the manifest that should be treated as deleted. This 
allows marking manifest
+   * entries as deleted without rewriting the manifest file.
+   *
+   * <p>Optional for DATA_MANIFEST and DELETE_MANIFEST content types, must be 
null otherwise.
+   */
+  ByteBuffer manifestDV();
+
+  /** Returns metadata about how this file is encrypted, or null if stored in 
plain text. */
+  ByteBuffer keyMetadata();
+
+  /**
+   * Returns list of recommended split locations, if applicable, null 
otherwise.
+   *
+   * <p>Must be sorted in ascending order.
+   */
+  List<Long> splitOffsets();
+
+  /**
+   * Returns the set of field IDs used for equality comparison, in equality 
delete files.
+   *
+   * <p>Required when content_type is EQUALITY_DELETES, must be null otherwise.
+   */
+  List<Integer> equalityIds();
+
+  /**
+   * Returns the location of the referenced file.
+   *
+   * <p>For POSITION_DELETES: location of the data file that the deletion 
vector references.
+   *
+   * <p>For DELETE_MANIFEST: location of the affiliated data manifest, or null 
if unaffiliated.
+   */
+  String referencedFile();
+
+  /**
+   * Copies this tracked file.
+   *
+   * <p>Manifest readers can reuse file instances; use this method to copy 
data when collecting
+   * files from tasks.
+   */
+  TrackedFile copy();
+
+  /**
+   * Copies this tracked file without stats.
+   *
+   * <p>Use this method to copy data without stats when collecting files.
+   */
+  TrackedFile copyWithoutStats();
+
+  /**
+   * Copies this tracked file with stats only for specific columns.
+   *
+   * <p>Manifest readers can reuse file instances; use this method to copy 
data with stats only for
+   * specific columns when collecting files.
+   *
+   * @param requestedColumnIds column IDs for which to keep stats
+   * @return a copy of this tracked file, with content stats for only the 
requested columns
+   */
+  TrackedFile copyWithStats(Set<Integer> requestedColumnIds);
+
+  /**
+   * Returns the ordinal position in the manifest.
+   *
+   * <p>Used for applying manifest deletion vectors.
+   */
+  Long pos();

Review Comment:
   I was trying to be consistent with the existing `ContentFile.pos()` API that 
returns a `Long`.



##########
core/src/main/java/org/apache/iceberg/TrackedFile.java:
##########
@@ -0,0 +1,282 @@
+/*
+ * 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 java.util.Set;
+import org.apache.iceberg.types.Types;
+
+/**
+ * Represents a V4 content entry in a manifest file.
+ *
+ * <p>TrackedFile is the V4 equivalent of ContentFile. It provides a unified 
representation for all
+ * entry types in a V4 manifest: data files, delete files, manifests, and 
deletion vectors.
+ */
+interface TrackedFile {
+  // Field IDs from V4 specification
+  Types.NestedField TRACKING_INFO =
+      Types.NestedField.required(
+          147, "tracking_info", TrackingInfo.schema(), "Tracking information 
for this entry");
+  Types.NestedField CONTENT_TYPE =
+      Types.NestedField.required(
+          134,
+          "content_type",
+          Types.IntegerType.get(),
+          "Type of content: 0=DATA, 1=POSITION_DELETES, 2=EQUALITY_DELETES, 
3=DATA_MANIFEST, 4=DELETE_MANIFEST");
+  Types.NestedField LOCATION =
+      Types.NestedField.required(100, "location", Types.StringType.get(), 
"Location of the file");
+  Types.NestedField FILE_FORMAT =
+      Types.NestedField.required(
+          101,
+          "file_format",
+          Types.StringType.get(),
+          "String file format name: avro, orc, parquet, or puffin");
+  Types.NestedField PARTITION_SPEC_ID =
+      Types.NestedField.required(
+          149,
+          "partition_spec_id",
+          Types.IntegerType.get(),
+          "ID of partition spec used to write manifest or data/delete files");
+  Types.NestedField SORT_ORDER_ID =
+      Types.NestedField.optional(
+          140,
+          "sort_order_id",
+          Types.IntegerType.get(),
+          "ID representing sort order for this file. Can only be set if 
content_type is 0");
+  Types.NestedField RECORD_COUNT =
+      Types.NestedField.required(
+          103,
+          "record_count",
+          Types.LongType.get(),
+          "Number of records in this file, or the cardinality of a deletion 
vector");
+  Types.NestedField FILE_SIZE_IN_BYTES =
+      Types.NestedField.optional(
+          104, "file_size_in_bytes", Types.LongType.get(), "Total file size in 
bytes.");
+  Types.NestedField CONTENT_STATS =
+      Types.NestedField.optional(
+          146,
+          "content_stats",
+          Types.StructType.of(), // TODO: Define ContentStats structure per V4 
proposal
+          "Content statistics for this entry");
+  Types.NestedField KEY_METADATA =
+      Types.NestedField.optional(
+          131,
+          "key_metadata",
+          Types.BinaryType.get(),
+          "Implementation-specific key metadata for encryption");
+  Types.NestedField SPLIT_OFFSETS =
+      Types.NestedField.optional(
+          132,
+          "split_offsets",
+          Types.ListType.ofRequired(133, Types.LongType.get()),
+          "Split offsets for the data file. Must be sorted ascending");
+  Types.NestedField CONTENT_INFO =
+      Types.NestedField.optional(
+          148,
+          "content_info",
+          ContentInfo.schema(),
+          "Content info. Required when content_type is POSITION_DELETES, must 
be null otherwise");
+  Types.NestedField EQUALITY_IDS =
+      Types.NestedField.optional(
+          135,
+          "equality_ids",
+          Types.ListType.ofRequired(136, Types.IntegerType.get()),
+          "Field ids used to determine row equality in equality delete files. 
Required when content=2");
+  Types.NestedField REFERENCED_FILE =
+      Types.NestedField.optional(
+          143,
+          "referenced_file",
+          Types.StringType.get(),
+          "Location of data file that a DV references if content_type is 
POSITION_DELETES. "
+              + "Location of affiliated data manifest if content_type is 
DELETE_MANIFEST, or null if unaffiliated");
+  Types.NestedField MANIFEST_STATS =
+      Types.NestedField.optional(
+          150,
+          "manifest_stats",
+          ManifestStats.schema(),
+          "Manifest statistics. Required for DATA_MANIFEST and 
DELETE_MANIFEST");
+  Types.NestedField MANIFEST_DV =
+      Types.NestedField.optional(
+          151,
+          "manifest_dv",
+          Types.BinaryType.get(),
+          "Serialized deletion vector marking deleted entry positions in the 
referenced manifest. "
+              + "Optional for DATA_MANIFEST and DELETE_MANIFEST, must be null 
for other content types");
+
+  /**
+   * Returns the path of the manifest which this file is referenced in or null 
if it was not read
+   * from a manifest.
+   */
+  String manifestLocation();
+
+  /**
+   * Returns the tracking information for this entry.
+   *
+   * <p>Contains status, snapshot ID, sequence numbers, and first-row-id. 
Optional - may be null if
+   * tracking info is inherited.
+   */
+  TrackingInfo trackingInfo();
+
+  /**
+   * Returns the type of content stored by this entry.
+   *
+   * <p>One of: DATA, POSITION_DELETES, EQUALITY_DELETES, DATA_MANIFEST, or 
DELETE_MANIFEST.
+   */
+  FileContent contentType();
+
+  /** Returns the location of the file. */
+  String location();
+
+  /** Returns the format of the file (avro, orc, parquet, or puffin). */
+  FileFormat fileFormat();
+
+  /**
+   * Returns the content info.
+   *
+   * <p>Must be defined if content_type is POSITION_DELETES, must be null 
otherwise.
+   */
+  ContentInfo contentInfo();
+
+  /** Returns the ID of the partition spec used to write this file or 
manifest. */
+  int partitionSpecId();
+
+  /**
+   * Returns the ID representing sort order for this file.
+   *
+   * <p>Can only be set if content_type is DATA.
+   */
+  Integer sortOrderId();
+
+  /** Returns the number of records in this file, or the cardinality of a 
deletion vector. */
+  long recordCount();
+
+  /**
+   * Returns the total file size in bytes.
+   *
+   * <p>Must be defined if location is defined.
+   */
+  Long fileSizeInBytes();

Review Comment:
   That makes sense. I changed the proposal (left it as a suggestion). I think 
we had it optional when we had inline manifest DVs as a separate record, which 
is not the case anymore.



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