rdblue commented on a change in pull request #2465:
URL: https://github.com/apache/iceberg/pull/2465#discussion_r615319740
##########
File path: core/src/test/java/org/apache/iceberg/TestSchemaUpdate.java
##########
@@ -1223,4 +1223,98 @@ public void testMoveBetweenStructsFails() {
.moveBefore("s2.x", "s1.a")
.apply());
}
+
+ @Test
+ public void testAddIdentifierField() {
+ Schema newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID)
+ .allowIncompatibleChanges()
+ .addIdentifierField("id")
+ .addRequiredColumn("id2", Types.StringType.get())
+ .addIdentifierField("id2")
+ .apply();
+ Assert.assertEquals(Sets.newHashSet(1, SCHEMA_LAST_COLUMN_ID + 1),
newSchema.identifierFieldIds());
+
+ AssertHelpers.assertThrows("Should fail if column with name not exist",
+ IllegalArgumentException.class,
+ "Cannot find column of the given name in existing or newly added
columns",
+ () -> new SchemaUpdate(SCHEMA,
SCHEMA_LAST_COLUMN_ID).addIdentifierField("unknown").apply());
+
+ AssertHelpers.assertThrows("Should fail if column with name not exist",
+ IllegalArgumentException.class,
+ "it is not a required field",
+ () -> new SchemaUpdate(SCHEMA,
SCHEMA_LAST_COLUMN_ID).addIdentifierField("data").apply());
+
+ AssertHelpers.assertThrows("Should fail if column with name not exist",
+ IllegalArgumentException.class,
+ "it is not a primitive field",
+ () -> new SchemaUpdate(SCHEMA,
SCHEMA_LAST_COLUMN_ID).addIdentifierField("locations").apply());
+ }
+
+ @Test
+ public void testRenameIdentifierField() {
+ Schema schemaWithIdentifierFields = new SchemaUpdate(SCHEMA,
SCHEMA_LAST_COLUMN_ID)
+ .allowIncompatibleChanges()
+ .addIdentifierField("id")
+ .apply();
+
+ Schema newSchema = new SchemaUpdate(schemaWithIdentifierFields,
SCHEMA_LAST_COLUMN_ID)
+ .renameColumn("id", "id2")
+ .apply();
+
+ Assert.assertEquals(Sets.newHashSet(1), newSchema.identifierFieldIds());
+ }
+
+ @Test
+ public void testMoveIdentifierField() {
+ Schema schemaWithIdentifierFields = new SchemaUpdate(SCHEMA,
SCHEMA_LAST_COLUMN_ID)
+ .allowIncompatibleChanges()
+ .addIdentifierField("id")
+ .apply();
+
+ Schema newSchema = new SchemaUpdate(schemaWithIdentifierFields,
SCHEMA_LAST_COLUMN_ID)
+ .moveAfter("id", "locations")
+ .apply();
+ Assert.assertEquals(Sets.newHashSet(1), newSchema.identifierFieldIds());
+
+ newSchema = new SchemaUpdate(schemaWithIdentifierFields,
SCHEMA_LAST_COLUMN_ID)
+ .moveBefore("id", "locations")
+ .apply();
+ Assert.assertEquals(Sets.newHashSet(1), newSchema.identifierFieldIds());
+
+ newSchema = new SchemaUpdate(schemaWithIdentifierFields,
SCHEMA_LAST_COLUMN_ID)
+ .moveFirst("id")
+ .apply();
+ Assert.assertEquals(Sets.newHashSet(1), newSchema.identifierFieldIds());
+ }
+
+ @Test
+ public void testRemoveIdentifierField() {
+ Schema schemaWithIdentifierFields = new SchemaUpdate(SCHEMA,
SCHEMA_LAST_COLUMN_ID)
+ .allowIncompatibleChanges()
+ .addIdentifierField("id")
+ .apply();
+
+ AssertHelpers.assertThrows("Should fail if deleting column before deleting
it as identifier field",
+ IllegalArgumentException.class,
+ "Cannot delete a column that is an identifier field",
Review comment:
Does this error message include the column name that the user wanted to
delete?
--
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]