rdblue commented on a change in pull request #922:
URL: https://github.com/apache/iceberg/pull/922#discussion_r449921239



##########
File path: api/src/test/java/org/apache/iceberg/TestPartitionSpecValidation.java
##########
@@ -241,11 +263,45 @@ public void 
testAddPartitionFieldsWithAndWithoutFieldIds() {
         .add(1, "id_partition2", "bucket[5]")
         .add(1, 1005, "id_partition1", "bucket[4]")
         .truncate("s", 1, "custom_truncate")
+        .add(1, 1002, "id_partition3", "bucket[3]")
         .build();
 
     Assert.assertEquals(1000, spec.fields().get(0).fieldId());
     Assert.assertEquals(1005, spec.fields().get(1).fieldId());
     Assert.assertEquals(1006, spec.fields().get(2).fieldId());
+    Assert.assertEquals(1002, spec.fields().get(3).fieldId());
     Assert.assertEquals(1006, spec.lastAssignedFieldId());
   }
+
+  @Test
+  public void testAddPartitionFieldsWithInvalidFieldId() {
+    AssertHelpers.assertThrows("Should detect invalid duplicate field id",
+        IllegalArgumentException.class,
+        "Cannot add a partition that duplicates another within",
+        () -> PartitionSpec.builderFor(SCHEMA)
+            .add(1, "id_partition2", "bucket[5]")
+            .add(1, 1005, "id_partition1", "bucket[4]")
+            .add(1, 1005, "id_partition3", "bucket[3]")
+            .build());
+  }
+
+  @Test
+  public void testMultipleBucketPartitions() {
+    AssertHelpers.assertThrows("Should not allow bucket[8](id) and 
bucket[16](id)",
+        IllegalArgumentException.class, "Cannot use partition name more than 
once",
+        () -> PartitionSpec.builderFor(SCHEMA)
+            .bucket("id", 8, "bucket")
+            .bucket("s", 16, "bucket").build());
+
+    AssertHelpers.assertThrows("Should not allow bucket[8](id) and 
bucket[16](id)",
+        IllegalArgumentException.class, "Cannot add redundant partition",
+        () -> PartitionSpec.builderFor(SCHEMA).bucket("id", 8).bucket("id", 
16).build());
+
+    AssertHelpers.assertThrows("Should not allow bucket[8](id) and 
bucket[16](id)",
+        IllegalArgumentException.class, "Cannot add redundant partition",
+        () -> PartitionSpec.builderFor(SCHEMA)
+            .bucket("id", 8, "id_bucket1")
+            .bucket("id", 16, "id_bucket2").build());
+

Review comment:
       Nit: unnecessary empty line.




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



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

Reply via email to