rdblue commented on a change in pull request #2465:
URL: https://github.com/apache/iceberg/pull/2465#discussion_r615319469
##########
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());
Review comment:
Would it be better to use
`Sets.newHashSet(SCHEMA.findField("id").fieldId())` instead of assuming the ID?
--
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]