nastra commented on code in PR #10861: URL: https://github.com/apache/iceberg/pull/10861#discussion_r1718128857
########## core/src/test/java/org/apache/iceberg/TestFormatVersions.java: ########## @@ -23,56 +23,95 @@ import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import org.junit.jupiter.api.TestTemplate; public class TestFormatVersions extends TestBase { @Parameters(name = "formatVersion = {0}") protected static List<Object> parameters() { - return Arrays.asList(1); + return Arrays.asList(1, 2); } @TestTemplate public void testDefaultFormatVersion() { - assertThat(table.ops().current().formatVersion()).isEqualTo(1); + assertThat(table.ops().current().formatVersion()).isEqualTo(formatVersion); } @TestTemplate public void testFormatVersionUpgrade() { TableOperations ops = table.ops(); - TableMetadata base = ops.current(); - ops.commit(base, base.upgradeToFormatVersion(2)); + int newFormatVersion = formatVersion + 1; + + TableMetadata newTableMetadata = ops.current().upgradeToFormatVersion(newFormatVersion); + + assertThat( + newTableMetadata.changes().stream() + .filter(MetadataUpdate.UpgradeFormatVersion.class::isInstance) + .map(MetadataUpdate.UpgradeFormatVersion.class::cast) + .map(MetadataUpdate.UpgradeFormatVersion::formatVersion)) + .containsExactly(newFormatVersion); + + ops.commit(ops.current(), newTableMetadata); - assertThat(ops.current().formatVersion()).isEqualTo(2); + assertThat(ops.current().formatVersion()).isEqualTo(newFormatVersion); + } + + @TestTemplate + public void testFormatVersionUpgradeToLatest() { + TableOperations ops = table.ops(); + int newFormatVersion = TableMetadata.SUPPORTED_TABLE_FORMAT_VERSION; + + TableMetadata newTableMetadata = ops.current().upgradeToFormatVersion(newFormatVersion); + + // check that non-incremental updates are syntactic sugar for serial updates. E.g. upgrading + // from V1 to V3 will register changes in the table metadata for upgrading to V2 and V3 in + // order (V1->V2->V3) + assertThat( Review Comment: based on my last comment in https://github.com/apache/iceberg/pull/10861/files#r1718122028 around supporting a direct 1 -> 3 upgrade I believe you only need to remove this check here (or adjust it to only verify that there's a single `MetadataUpdate.UpgradeFormatVersion` instance if you prefer that). Given that the new format version in this test always points to 3, everything else in this test is still valid, so you don't really need to change much in terms of testing -- 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