rdblue commented on a change in pull request #2096:
URL: https://github.com/apache/iceberg/pull/2096#discussion_r580683983
##########
File path: core/src/test/java/org/apache/iceberg/TestTableMetadata.java
##########
@@ -599,4 +639,81 @@ public void testUpdateSortOrder() {
Assert.assertEquals("Should be nulls first",
NullOrder.NULLS_FIRST,
sortedByX.sortOrder().fields().get(0).nullOrder());
}
+
+ @Test
+ public void testUpdateSchema() {
+ Schema schema = new Schema(0,
+ Types.NestedField.required(1, "y", Types.LongType.get(), "comment")
+ );
+ TableMetadata freshTable = TableMetadata.newTableMetadata(
+ schema, PartitionSpec.unpartitioned(), null, ImmutableMap.of());
+ Assert.assertEquals("Should use TableMetadata.INITIAL_SCHEMA_ID for
current schema id",
+ TableMetadata.INITIAL_SCHEMA_ID, freshTable.currentSchemaId());
+ assertSameSchemaList(ImmutableList.of(schema), freshTable.schemas());
+ Assert.assertEquals("Should have expected schema upon return",
+ schema.asStruct(), freshTable.schema().asStruct());
+ Assert.assertEquals("Should return expected last column id", 1,
freshTable.lastColumnId());
+
+ // update schema
+ Schema schema2 = new Schema(
+ Types.NestedField.required(1, "y", Types.LongType.get(), "comment"),
+ Types.NestedField.required(2, "x", Types.StringType.get())
+ );
+ TableMetadata twoSchemasTable = freshTable.updateSchema(schema2, 2);
+ Assert.assertEquals("Should have current schema id as 1",
+ 1, twoSchemasTable.currentSchemaId());
+ assertSameSchemaList(ImmutableList.of(schema, new Schema(1,
schema2.columns())),
+ twoSchemasTable.schemas());
+ Assert.assertEquals("Should have expected schema upon return",
+ schema2.asStruct(), twoSchemasTable.schema().asStruct());
+ Assert.assertEquals("Should return expected last column id", 2,
twoSchemasTable.lastColumnId());
+
+ // update schema with the the same schema and last column ID as current
shouldn't cause change
+ Schema sameSchema2 = new Schema(
+ Types.NestedField.required(1, "y", Types.LongType.get(), "comment"),
+ Types.NestedField.required(2, "x", Types.StringType.get())
+ );
+ TableMetadata sameSchemaTable = twoSchemasTable.updateSchema(sameSchema2,
2);
+ Assert.assertEquals("Should return same table metadata",
+ twoSchemasTable, sameSchemaTable);
Review comment:
Should this use `assertSame` since the object must be the same
`TableMetadata` instance and not just equal to it?
----------------------------------------------------------------
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]