zhangbutao commented on code in PR #6482: URL: https://github.com/apache/iceberg/pull/6482#discussion_r1089690341
########## core/src/test/java/org/apache/iceberg/TestTableUpdatePartitionSpec.java: ########## @@ -187,6 +188,53 @@ public void testRemoveAndAddField() { Assert.assertEquals(1001, table.spec().lastAssignedFieldId()); } + @Test + public void testAddAfterRemoveTimeField() { + table.updateSpec().addField(year("year_field")).commit(); + + PartitionSpec newSpec = PartitionSpec.builderFor(table.schema()) + .withSpecId(1) + .bucket("data", 16) + .year("year_field") + .build(); + + Assert.assertEquals( + "Should have same transform class: org.apache.iceberg.transforms.Years", + newSpec.fields().get(1).transform().getClass().getName(), + table.spec().fields().get(1).transform().getClass().getName()); + + V1Assert.assertEquals("Should add a new id year", newSpec, table.spec()); + V2Assert.assertEquals( + "Should add a new id year", + PartitionSpec.builderFor(table.schema()) + .withSpecId(1) + .add(2, 1000, "data_bucket", Transforms.bucket(16)) + .add(3, 1001, "year_field_year", Transforms.year()) + .build(), + table.spec()); + + // remove and add a field with TimeTransform(Years, Months, Days, Hours) + table.updateSpec().removeField("year_field_year").addField(year("year_field")).commit(); + + V1Assert.assertEquals( + "Should remove and then add a year field", + PartitionSpec.builderFor(table.schema()) + .withSpecId(1) + .bucket("data", 16) + .year("year_field") + .build(), + table.spec()); + V2Assert.assertEquals( Review Comment: 1. test1: adding a year field to the spec(`table.updateSpec().addField(year("year_field")).commit()`;) I want to verify if the actual table transform type is same as `PartitionSpec.builderFor` and the transform type class should be `org.apache.iceberg.transforms.Years`. If not same, the test2 will also faill. 2. test2: `table.updateSpec().removeField("year_field_year").addField(year("year_field")).commit()`; Because i have encountered exception when **removed and then add a same field**, i want to check if this could work after the fix. To be exact, test2 is a e2e test. -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org