rambleraptor commented on code in PR #16572:
URL: https://github.com/apache/iceberg/pull/16572#discussion_r3313174185


##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -1133,6 +1133,64 @@ public void testParserVersionValidation() throws 
Exception {
         .hasMessageStartingWith("Cannot read unsupported version");
   }
 
+  @ParameterizedTest
+  @ValueSource(ints = {1, 2, 3})
+  public void testLocationRequiredBeforeV4(int formatVersion) {
+    assertThatThrownBy(
+            () ->
+                TableMetadata.newTableMetadata(
+                    TEST_SCHEMA,
+                    PartitionSpec.unpartitioned(),
+                    SortOrder.unsorted(),
+                    null,
+                    ImmutableMap.of(),
+                    formatVersion))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Table location is required in format v%s", formatVersion);
+  }
+
+  @ParameterizedTest
+  @ValueSource(ints = {1, 2, 3})
+  public void testParserRequiresLocationBeforeV4(int formatVersion) {
+    TableMetadata metadata =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA,
+            PartitionSpec.unpartitioned(),
+            SortOrder.unsorted(),
+            TEST_LOCATION,
+            ImmutableMap.of(),
+            formatVersion);
+    // drop the location field to simulate a v1-v3 metadata file that omits 
the required location
+    String withoutLocation =
+        TableMetadataParser.toJson(metadata)
+            .replaceFirst("\"location\"\\s*:\\s*\"[^\"]*\"\\s*,", "");

Review Comment:
   I like that so much more. I really dislike regexes, but that seemed easier 
at the time.



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

Reply via email to