manishmalhotrawork commented on a change in pull request #666: 
BaseRewriteManifests should keep different manifest for different partitionSpec
URL: https://github.com/apache/incubator-iceberg/pull/666#discussion_r357441161
 
 

 ##########
 File path: core/src/test/java/org/apache/iceberg/TestRewriteManifests.java
 ##########
 @@ -392,6 +392,150 @@ public void testBasicManifestReplacement() throws 
IOException {
         statuses(ManifestEntry.Status.ADDED, ManifestEntry.Status.ADDED));
   }
 
+  @Test
+  public void testWithMultiplePartitionSpec() throws IOException {
+    Assert.assertNull("Table should be empty", table.currentSnapshot());
+
+    table.newAppend()
+        .appendFile(FILE_A)
+        .appendFile(FILE_B)
+        .commit();
+
+    TableMetadata base = readMetadata();
+    Assert.assertEquals("Should create 1 manifest for initial write",
+        1, base.currentSnapshot().manifests().size());
+    ManifestFile initialManifest = base.currentSnapshot().manifests().get(0);
+
+    int initialPartitionSpecId = initialManifest.partitionSpecId();
+
+    // build the new spec using the table's schema, which uses fresh IDs
+    PartitionSpec newSpec = PartitionSpec.builderFor(base.schema())
+        .bucket("data", 16)
+        .bucket("id", 4)
+        .build();
+
+    // commit the new partition spec to the table manually
+    table.ops().commit(base, base.updatePartitionSpec(newSpec));
+
+    DataFile newFileC = DataFiles.builder(newSpec)
+        .copy(FILE_C)
+        .withPartitionPath("data_bucket=2/id_bucket=3")
+        .build();
+
+    table.newAppend()
+        .appendFile(newFileC)
+        .commit();
+
+    DataFile newFileD = DataFiles.builder(newSpec)
+        .copy(FILE_D)
+        .withPartitionPath("data_bucket=2/id_bucket=4")
+        .build();
+
+    table.newAppend()
+        .appendFile(newFileD)
+        .commit();
+
+    Assert.assertEquals("Should use 3 manifest files",
+        3, table.currentSnapshot().manifests().size());
+
+    RewriteManifests rewriteManifests = table.rewriteManifests();
+    // try to cluster in 1 manifest file, but because of 2 partition specs
+    // we should still have 2 manifest files.
+    rewriteManifests.clusterBy(dataFile -> "file").commit();
+    List<ManifestFile> manifestFiles = table.currentSnapshot().manifests();
+
+    Assert.assertEquals("Rewrite manifest should produce 2 manifest files",
+        2, manifestFiles.size());
+
+    Assert.assertEquals("2 manifest files should have different 
partitionSpecId",
+        true, manifestFiles.get(0).partitionSpecId() != 
manifestFiles.get(1).partitionSpecId());
+
+    matchNumberOfManifestFileWithSpecId(manifestFiles, initialPartitionSpecId, 
1);
+
+    matchNumberOfManifestFileWithSpecId(manifestFiles, 
table.ops().current().spec().specId(), 1);
+
+    Assert.assertEquals("first manifest file should have 2 data files",
+        Integer.valueOf(2), manifestFiles.get(0).existingFilesCount());
+
+    Assert.assertEquals("second manifest file should have 2 data files",
+        Integer.valueOf(2), manifestFiles.get(1).existingFilesCount());
+
+  }
+
+  @Test
+  public void testManifestSizeWithMultiplePartitionSpec() throws IOException {
+    Assert.assertNull("Table should be empty", table.currentSnapshot());
+
+    table.newAppend()
+        .appendFile(FILE_A)
+        .appendFile(FILE_B)
+        .commit();
+
+    TableMetadata base = readMetadata();
+    Assert.assertEquals("Should create 1 manifest for initial write",
+        1, base.currentSnapshot().manifests().size());
+    ManifestFile initialManifest = base.currentSnapshot().manifests().get(0);
+    int initialPartitionSpecId = initialManifest.partitionSpecId();
+
+    // build the new spec using the table's schema, which uses fresh IDs
+    PartitionSpec newSpec = PartitionSpec.builderFor(base.schema())
+        .bucket("data", 16)
+        .bucket("id", 4)
+        .build();
+
+    // commit the new partition spec to the table manually
+    table.ops().commit(base, base.updatePartitionSpec(newSpec));
+
+    DataFile newFileC = DataFiles.builder(newSpec)
+        .copy(FILE_C)
+        .withPartitionPath("data_bucket=2/id_bucket=3")
+        .build();
+
+    table.newAppend()
+        .appendFile(newFileC)
+        .commit();
+
+    DataFile newFileD = DataFiles.builder(newSpec)
+        .copy(FILE_D)
+        .withPartitionPath("data_bucket=2/id_bucket=4")
+        .build();
+
+    table.newAppend()
+        .appendFile(newFileD)
+        .commit();
+
+    Assert.assertEquals("Rewrite manifests should produce 2 manifest files",
+        3, table.currentSnapshot().manifests().size());
+
+    // cluster by constant will combine manifests into one but small target 
size will create one per entry
+    BaseRewriteManifests rewriteManifests = spy((BaseRewriteManifests) 
table.rewriteManifests());
+    when(rewriteManifests.getManifestTargetSizeBytes()).thenReturn(1L);
+
+    // try to cluster in 1 manifest file, but because of 2 partition specs
 
 Review comment:
   done. it was incorrect.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to