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


##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -552,6 +609,511 @@ public ManifestFile copy() {
     }
   }
 
+  /** Shared base for content-file (DATA / EQUALITY_DELETES) write-direction 
wrappers. */
+  abstract static class ContentTrackedFile<F extends ContentFile<F>>
+      implements TrackedFile, StructLike {
+    private final Types.StructType partitionType;
+    private final MapBackedContentStats statsWrapper;
+
+    private Tracking tracking;
+    private F file;
+    private StructProjection partition;
+    private ContentStats stats;
+
+    ContentTrackedFile(Schema writeSchema) {
+      Preconditions.checkArgument(writeSchema != null, "Invalid write schema: 
null");
+      Types.StructType statsType = nestedStruct(writeSchema, 
TrackedFile.CONTENT_STATS_ID);
+      this.partitionType = nestedStruct(writeSchema, TrackedFile.PARTITION_ID);
+      this.statsWrapper = statsType != null ? new 
MapBackedContentStats(statsType) : null;
+    }
+
+    TrackedFile wrapWithTracking(F newFile, Tracking newTracking) {
+      Preconditions.checkArgument(newFile != null, "Invalid file: null");
+      Preconditions.checkArgument(newTracking != null, "Invalid tracking: 
null");
+      validateContent(newFile);
+
+      if (newFile instanceof TrackedContentFile) {
+        return ((TrackedContentFile<?>) newFile).file();
+      }
+
+      this.file = newFile;
+      this.partition = partitionType != null ? projectPartition(newFile, 
partitionType) : null;
+      this.stats = statsWrapper != null ? statsWrapper.wrap(newFile) : null;
+      this.tracking = newTracking;
+      return this;
+    }
+
+    /** Content-type-specific validation of the wrapped file. */
+    abstract void validateContent(F newFile);
+
+    protected F file() {
+      return file;
+    }
+
+    @Override
+    public Tracking tracking() {
+      return tracking;
+    }
+
+    @Override
+    public int formatVersion() {
+      return TableMetadata.MIN_FORMAT_VERSION_PARQUET_MANIFESTS;

Review Comment:
   I don't think that this is correct. The format version is determined at 
write time so we can't default it like this. I think that this should probably 
fail. That's the safest option.
   
   @anoopj, I think we should revisit the `formatVersion=-1` default in 
`TrackedFileStruct`. I think it should probably default to `null` so that 
accessing it fails if it is not set.



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