jiwen624 commented on code in PR #18812:
URL: https://github.com/apache/iceberg/pull/18812#discussion_r4533955854
##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -1710,6 +1710,104 @@ schema, new Schema(1, schema2.columns()), new Schema(2,
schema3.columns())),
assertThat(threeSchemaTable.lastColumnId()).isEqualTo(6);
}
+ @Test
+ void setCurrentSchemaToReAddedHistoricalSchema() {
+ Schema original = new Schema(Types.NestedField.required(1, "x",
Types.LongType.get()));
+ TableMetadata base =
+ TableMetadata.newTableMetadata(
+ original, PartitionSpec.unpartitioned(), TEST_LOCATION,
ImmutableMap.of());
+ TableMetadata updated =
+ base.updateSchema(
+ new Schema(
+ Types.NestedField.required(1, "x", Types.LongType.get()),
+ Types.NestedField.optional(2, "y", Types.StringType.get())));
+
+ TableMetadata reverted =
+
TableMetadata.buildFrom(updated).addSchema(original).setCurrentSchema(-1).build();
+
+ assertThat(reverted.currentSchemaId()).isEqualTo(base.currentSchemaId());
+ assertThat(reverted.changes()).hasSize(updated.changes().size() + 1);
+ assertThat(Iterables.getLast(reverted.changes()))
+ .isInstanceOfSatisfying(
+ MetadataUpdate.SetCurrentSchema.class,
+ update ->
assertThat(update.schemaId()).isEqualTo(base.currentSchemaId()));
+ }
+
+ @Test
+ void setDefaultSpecToReAddedHistoricalSpec() {
+ Schema schema = new Schema(Types.NestedField.required(1, "x",
Types.LongType.get()));
+ TableMetadata base =
+ TableMetadata.newTableMetadata(
+ schema, PartitionSpec.unpartitioned(), TEST_LOCATION,
ImmutableMap.of());
+ TableMetadata updated =
+
base.updatePartitionSpec(PartitionSpec.builderFor(base.schema()).bucket("x",
4).build());
+
+ TableMetadata reverted =
+ TableMetadata.buildFrom(updated)
+ .addPartitionSpec(PartitionSpec.unpartitioned())
+ .setDefaultPartitionSpec(-1)
+ .build();
+
+ assertThat(reverted.defaultSpecId()).isEqualTo(base.defaultSpecId());
+ assertThat(reverted.changes()).hasSize(updated.changes().size() + 1);
+ assertThat(Iterables.getLast(reverted.changes()))
+ .isInstanceOfSatisfying(
+ MetadataUpdate.SetDefaultPartitionSpec.class,
+ update ->
assertThat(update.specId()).isEqualTo(base.defaultSpecId()));
+ }
+
+ @Test
+ void setDefaultSortOrderToReAddedHistoricalSortOrder() {
+ Schema schema = new Schema(Types.NestedField.required(1, "x",
Types.LongType.get()));
+ TableMetadata base =
+ TableMetadata.newTableMetadata(
+ schema, PartitionSpec.unpartitioned(), TEST_LOCATION,
ImmutableMap.of());
+ TableMetadata updated =
+
base.replaceSortOrder(SortOrder.builderFor(base.schema()).asc("x").build());
+
+ TableMetadata reverted =
+ TableMetadata.buildFrom(updated)
+ .addSortOrder(SortOrder.unsorted())
+ .setDefaultSortOrder(-1)
+ .build();
+
+
assertThat(reverted.defaultSortOrderId()).isEqualTo(base.defaultSortOrderId());
+ assertThat(reverted.changes()).hasSize(updated.changes().size() + 1);
+ assertThat(Iterables.getLast(reverted.changes()))
+ .isInstanceOfSatisfying(
+ MetadataUpdate.SetDefaultSortOrder.class,
+ update ->
assertThat(update.sortOrderId()).isEqualTo(base.defaultSortOrderId()));
+ }
+
+ @Test
+ void replayedChangesSetCurrentSchemaToReAddedSchema() {
Review Comment:
This seems to cover schemas only. How about the specs and sort orders which
are also changed?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]