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


##########
core/src/test/java/org/apache/iceberg/TestTrackedFileAdapters.java:
##########
@@ -276,6 +282,156 @@ void testDVDeleteFileAdapterRejectsNullDeletionVector() {
         .hasMessage("Cannot create DV delete file: no deletion vector");
   }
 
+  @ParameterizedTest
+  @EnumSource(
+      value = FileContent.class,
+      names = {"DATA_MANIFEST", "DELETE_MANIFEST"})
+  void testManifestFileAdapterDelegation(FileContent contentType) {
+    ManifestInfo manifestInfo = createManifestInfo();
+    TrackedFile file =
+        manifestBuilder(contentType)
+            .manifestInfo(manifestInfo)
+            .keyMetadata(ByteBuffer.wrap(new byte[] {7, 8, 9}))
+            .build();
+    populateTrackingFields(file);
+
+    ManifestFile manifest = TrackedFileAdapters.asManifestFile(file);
+
+    ManifestContent expectedContent =
+        contentType == FileContent.DATA_MANIFEST ? ManifestContent.DATA : 
ManifestContent.DELETES;
+    assertThat(manifest.path()).isEqualTo(MANIFEST_FILE_LOCATION);
+    assertThat(manifest.length()).isEqualTo(MANIFEST_FILE_SIZE);
+    assertThat(manifest.content()).isEqualTo(expectedContent);
+    assertThat(manifest.copy().content()).isEqualTo(expectedContent);
+    assertThat(manifest.sequenceNumber()).isEqualTo(DATA_SEQUENCE_NUMBER);
+    
assertThat(manifest.minSequenceNumber()).isEqualTo(manifestInfo.minSequenceNumber());
+    assertThat(manifest.snapshotId()).isEqualTo(SNAPSHOT_ID);
+    
assertThat(manifest.addedFilesCount()).isEqualTo(manifestInfo.addedFilesCount());
+    
assertThat(manifest.addedRowsCount()).isEqualTo(manifestInfo.addedRowsCount());
+    
assertThat(manifest.existingFilesCount()).isEqualTo(manifestInfo.existingFilesCount());
+    
assertThat(manifest.existingRowsCount()).isEqualTo(manifestInfo.existingRowsCount());
+    
assertThat(manifest.deletedFilesCount()).isEqualTo(manifestInfo.deletedFilesCount());
+    
assertThat(manifest.deletedRowsCount()).isEqualTo(manifestInfo.deletedRowsCount());
+    assertThat(manifest.firstRowId()).isEqualTo(FIRST_ROW_ID);
+    assertThat(manifest.keyMetadata()).isEqualTo(ByteBuffer.wrap(new byte[] 
{7, 8, 9}));
+    assertThat(manifest.partitions()).isNull();
+  }
+
+  @Test
+  void testManifestFileAdapterPartitionSpecIdUnsupported() {
+    TrackedFile file = manifestFile(FileContent.DATA_MANIFEST, 
createManifestInfo());
+
+    ManifestFile manifest = TrackedFileAdapters.asManifestFile(file);
+
+    assertThatThrownBy(manifest::partitionSpecId)
+        .isInstanceOf(UnsupportedOperationException.class)
+        .hasMessage("v4 manifests are not bound to a single partition spec");
+  }
+
+  @Test
+  void testManifestFileAdapterRejectsManifestWithDeletionVector() {
+    ManifestInfo manifestInfo =
+        ManifestInfoStruct.builder()
+            .addedFilesCount(3)
+            .existingFilesCount(5)
+            .deletedFilesCount(2)
+            .replacedFilesCount(0)
+            .addedRowsCount(300L)
+            .existingRowsCount(500L)
+            .deletedRowsCount(200L)
+            .replacedRowsCount(0L)
+            .minSequenceNumber(7L)
+            .dv(ByteBuffer.wrap(new byte[] {1, 2, 3}))
+            .dvCardinality(4L)
+            .build();
+    TrackedFile file = manifestFile(FileContent.DATA_MANIFEST, manifestInfo);
+
+    assertThatThrownBy(() -> TrackedFileAdapters.asManifestFile(file))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage(
+            "Cannot adapt manifest with a deletion vector to ManifestFile: %s",
+            MANIFEST_FILE_LOCATION);
+  }
+
+  @Test
+  void testManifestFileAdapterReturnsNullForUnsetNullableFields() {
+    TrackedFile file =
+        
manifestBuilder(FileContent.DATA_MANIFEST).manifestInfo(createManifestInfo()).build();
+    // Inheritance fills the data sequence number, which the adapter requires; 
first row ID and
+    // key metadata stay unset.
+    ((TrackingStruct) file.tracking()).set(DATA_SEQUENCE_NUMBER_ORDINAL, 
DATA_SEQUENCE_NUMBER);

Review Comment:
   Routing through inheritFrom() will require building a parent `Tzracking` 
with several nulls. I prefer to keep it since this is simpler. 



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