leangjonathan commented on code in PR #10861:
URL: https://github.com/apache/iceberg/pull/10861#discussion_r1704792740


##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -1452,52 +1452,148 @@ public void testCreateV2MetadataThroughTableProperty() 
{
   }
 
   @Test
-  public void testReplaceV1MetadataToV2ThroughTableProperty() {
+  public void testReplaceMetadataThroughTableProperty() {
     Schema schema = new Schema(Types.NestedField.required(10, "x", 
Types.StringType.get()));
 
-    TableMetadata meta =
-        TableMetadata.newTableMetadata(
-            schema,
-            PartitionSpec.unpartitioned(),
-            null,
-            ImmutableMap.of(TableProperties.FORMAT_VERSION, "1", "key", 
"val"));
-
-    meta =
-        meta.buildReplacement(
-            meta.schema(),
-            meta.spec(),
-            meta.sortOrder(),
-            meta.location(),
-            ImmutableMap.of(TableProperties.FORMAT_VERSION, "2", "key2", 
"val2"));
-
-    assertThat(meta.formatVersion()).isEqualTo(2);
-    assertThat(meta.properties())
-        .containsEntry("key", "val")
-        .containsEntry("key2", "val2")
-        .doesNotContainKey(TableProperties.FORMAT_VERSION);
+    for (int baseTableVersion = 1;
+        baseTableVersion < TableMetadata.SUPPORTED_TABLE_FORMAT_VERSION;
+        baseTableVersion++) {
+      TableMetadata meta =
+          TableMetadata.newTableMetadata(
+              schema,
+              PartitionSpec.unpartitioned(),
+              null,
+              ImmutableMap.of(
+                  TableProperties.FORMAT_VERSION, 
String.valueOf(baseTableVersion), "key", "val"));
+
+      int newTableVersion = baseTableVersion + 1;
+      meta =
+          meta.buildReplacement(
+              meta.schema(),
+              meta.spec(),
+              meta.sortOrder(),
+              meta.location(),
+              ImmutableMap.of(
+                  TableProperties.FORMAT_VERSION, 
String.valueOf(newTableVersion), "key2", "val2"));
+
+      assertThat(meta.formatVersion()).isEqualTo(newTableVersion);
+      assertThat(meta.properties())
+          .containsEntry("key", "val")
+          .containsEntry("key2", "val2")
+          .doesNotContainKey(TableProperties.FORMAT_VERSION);
+    }
   }
 
   @Test
-  public void testUpgradeV1MetadataToV2ThroughTableProperty() {
-    Schema schema = new Schema(Types.NestedField.required(10, "x", 
Types.StringType.get()));
-
-    TableMetadata meta =
-        TableMetadata.newTableMetadata(
-            schema,
-            PartitionSpec.unpartitioned(),
-            null,
-            ImmutableMap.of(TableProperties.FORMAT_VERSION, "1", "key", 
"val"));
+  public void testReplaceMetadataThroughTablePropertySkipVersion() {
+    for (int baseTableVersion = 1;
+        baseTableVersion < TableMetadata.SUPPORTED_TABLE_FORMAT_VERSION;
+        baseTableVersion++) {
+      for (int newTableVersion = baseTableVersion + 2;
+          newTableVersion <= TableMetadata.SUPPORTED_TABLE_FORMAT_VERSION;
+          newTableVersion++) {
+        Schema schema = new Schema(Types.NestedField.required(10, "x", 
Types.StringType.get()));
+
+        TableMetadata meta =
+            TableMetadata.newTableMetadata(
+                schema,
+                PartitionSpec.unpartitioned(),
+                null,
+                ImmutableMap.of(
+                    TableProperties.FORMAT_VERSION,
+                    String.valueOf(baseTableVersion),
+                    "key",
+                    "val"));
+
+        final int finalNewTableVersion = newTableVersion;
+        assertThatThrownBy(
+                () ->
+                    meta.buildReplacement(
+                        meta.schema(),
+                        meta.spec(),
+                        meta.sortOrder(),
+                        meta.location(),
+                        ImmutableMap.of(
+                            TableProperties.FORMAT_VERSION,
+                            String.valueOf(finalNewTableVersion),
+                            "key2",
+                            "val2")))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage(
+                String.format(
+                    "Cannot skip format version(s) to upgrade v%d table to 
v%d",
+                    baseTableVersion, newTableVersion));
+      }
+    }
+  }
 
-    meta =
-        meta.replaceProperties(
-            ImmutableMap.of(TableProperties.FORMAT_VERSION, "2", "key2", 
"val2"));
+  @Test
+  public void testUpgradeMetadataThroughTableProperty() {

Review Comment:
   Added parameterization via a Streamed argument provider 



-- 
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

Reply via email to