nastra commented on code in PR #11444:
URL: https://github.com/apache/iceberg/pull/11444#discussion_r1830491512


##########
api/src/test/java/org/apache/iceberg/TestSchema.java:
##########
@@ -64,27 +59,77 @@ public class TestSchema {
               .withWriteDefault("--")
               .build());
 
+  private Schema generateTypeSchema(Type type) {
+    return new Schema(
+        Types.NestedField.required(1, "id", Types.LongType.get()),
+        Types.NestedField.optional(2, "top", type),
+        Types.NestedField.optional(3, "arr", Types.ListType.ofRequired(4, 
type)),
+        Types.NestedField.required(
+            5,
+            "struct",
+            Types.StructType.of(
+                Types.NestedField.optional(6, "inner_op", type),
+                Types.NestedField.required(7, "inner_req", type),
+                Types.NestedField.optional(
+                    8,
+                    "struct_arr",
+                    Types.StructType.of(Types.NestedField.optional(9, "deep", 
type))))));
+  }
+
+  private static Stream<Arguments> testTypeUnsupported() {
+    return TESTTYPES.stream()
+        .flatMap(
+            type ->
+                IntStream.range(1, MIN_FORMAT_VERSIONS.get(type.typeId()))
+                    .mapToObj(unsupportedVersion -> Arguments.of(type, 
unsupportedVersion)));
+  }
+
   @ParameterizedTest
-  @ValueSource(ints = {1, 2})
-  public void testUnsupportedTimestampNano(int formatVersion) {
-    assertThatThrownBy(() -> Schema.checkCompatibility(TS_NANO_CASES, 
formatVersion))
+  @MethodSource
+  public void testTypeUnsupported(Type type, int unsupportedVersion) {
+    assertThatThrownBy(
+            () -> Schema.checkCompatibility(generateTypeSchema(type), 
unsupportedVersion))
         .isInstanceOf(IllegalStateException.class)
         .hasMessage(
             "Invalid schema for v%s:\n"
-                + "- Invalid type for ts: timestamptz_ns is not supported 
until v3\n"
-                + "- Invalid type for arr.element: timestamp_ns is not 
supported until v3\n"
-                + "- Invalid type for struct.inner_ts: timestamptz_ns is not 
supported until v3\n"
-                + "- Invalid type for struct_arr.ts: timestamp_ns is not 
supported until v3",
-            formatVersion);
+                + "- Invalid type for top: %s is not supported until v%s\n"
+                + "- Invalid type for arr.element: %s is not supported until 
v%s\n"
+                + "- Invalid type for struct.inner_op: %s is not supported 
until v%s\n"
+                + "- Invalid type for struct.inner_req: %s is not supported 
until v%s\n"
+                + "- Invalid type for struct.struct_arr.deep: %s is not 
supported until v%s",
+            unsupportedVersion,
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()),
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()),
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()),
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()),
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()));
   }
 
-  @Test
-  public void testSupportedTimestampNano() {
-    assertThatCode(() -> Schema.checkCompatibility(TS_NANO_CASES, 
3)).doesNotThrowAnyException();
+  private static Stream<Arguments> testTypeSupported() {

Review Comment:
   ```suggestion
     private static Stream<Arguments> supportedTypes() {
   ```



##########
api/src/test/java/org/apache/iceberg/TestSchema.java:
##########
@@ -64,27 +59,77 @@ public class TestSchema {
               .withWriteDefault("--")
               .build());
 
+  private Schema generateTypeSchema(Type type) {
+    return new Schema(
+        Types.NestedField.required(1, "id", Types.LongType.get()),
+        Types.NestedField.optional(2, "top", type),
+        Types.NestedField.optional(3, "arr", Types.ListType.ofRequired(4, 
type)),
+        Types.NestedField.required(
+            5,
+            "struct",
+            Types.StructType.of(
+                Types.NestedField.optional(6, "inner_op", type),
+                Types.NestedField.required(7, "inner_req", type),
+                Types.NestedField.optional(
+                    8,
+                    "struct_arr",
+                    Types.StructType.of(Types.NestedField.optional(9, "deep", 
type))))));
+  }
+
+  private static Stream<Arguments> testTypeUnsupported() {
+    return TESTTYPES.stream()
+        .flatMap(
+            type ->
+                IntStream.range(1, MIN_FORMAT_VERSIONS.get(type.typeId()))
+                    .mapToObj(unsupportedVersion -> Arguments.of(type, 
unsupportedVersion)));
+  }
+
   @ParameterizedTest
-  @ValueSource(ints = {1, 2})
-  public void testUnsupportedTimestampNano(int formatVersion) {
-    assertThatThrownBy(() -> Schema.checkCompatibility(TS_NANO_CASES, 
formatVersion))
+  @MethodSource
+  public void testTypeUnsupported(Type type, int unsupportedVersion) {
+    assertThatThrownBy(
+            () -> Schema.checkCompatibility(generateTypeSchema(type), 
unsupportedVersion))
         .isInstanceOf(IllegalStateException.class)
         .hasMessage(
             "Invalid schema for v%s:\n"
-                + "- Invalid type for ts: timestamptz_ns is not supported 
until v3\n"
-                + "- Invalid type for arr.element: timestamp_ns is not 
supported until v3\n"
-                + "- Invalid type for struct.inner_ts: timestamptz_ns is not 
supported until v3\n"
-                + "- Invalid type for struct_arr.ts: timestamp_ns is not 
supported until v3",
-            formatVersion);
+                + "- Invalid type for top: %s is not supported until v%s\n"
+                + "- Invalid type for arr.element: %s is not supported until 
v%s\n"
+                + "- Invalid type for struct.inner_op: %s is not supported 
until v%s\n"
+                + "- Invalid type for struct.inner_req: %s is not supported 
until v%s\n"
+                + "- Invalid type for struct.struct_arr.deep: %s is not 
supported until v%s",
+            unsupportedVersion,
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()),
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()),
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()),
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()),
+            type,
+            MIN_FORMAT_VERSIONS.get(type.typeId()));
   }
 
-  @Test
-  public void testSupportedTimestampNano() {
-    assertThatCode(() -> Schema.checkCompatibility(TS_NANO_CASES, 
3)).doesNotThrowAnyException();
+  private static Stream<Arguments> testTypeSupported() {
+    return TESTTYPES.stream()
+        .flatMap(
+            type ->
+                IntStream.rangeClosed(MIN_FORMAT_VERSIONS.get(type.typeId()), 
MAX_FORMAT_VERSION)
+                    .mapToObj(supportedVersion -> Arguments.of(type, 
supportedVersion)));
   }
 
   @ParameterizedTest
-  @ValueSource(ints = {1, 2})
+  @MethodSource

Review Comment:
   ```suggestion
     @MethodSource(value = "supportedTypes")
   ```



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