amogh-jahagirdar commented on code in PR #17500:
URL: https://github.com/apache/iceberg/pull/17500#discussion_r3724681240


##########
core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java:
##########
@@ -966,6 +971,71 @@ public void testLoadTable() {
         .containsAll(properties.entrySet());
   }
 
+  @Test
+  public void testCreateTableWithVariantColumn() {

Review Comment:
   What about a schema evolution case? V3 table without variant and then later 
adding a variant column? 



##########
core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java:
##########
@@ -966,6 +971,71 @@ public void testLoadTable() {
         .containsAll(properties.entrySet());
   }
 
+  @Test
+  public void testCreateTableWithVariantColumn() {
+    assumeThat(supportsVariant()).as("Catalog supports the variant 
type").isTrue();
+
+    C catalog = catalog();
+
+    if (requiresNamespaceCreate()) {
+      catalog.createNamespace(TBL.namespace());
+    }
+
+    assertThat(catalog.tableExists(TBL)).as("Table should not 
exist").isFalse();
+
+    Schema variantSchema =
+        new Schema(
+            required(1, "id", Types.LongType.get()),
+            optional(2, "data", Types.VariantType.get()),
+            optional(3, "list_data", Types.ListType.ofOptional(5, 
Types.VariantType.get())),
+            optional(
+                4,
+                "map_data",
+                Types.MapType.ofOptional(6, 7, Types.StringType.get(), 
Types.VariantType.get())));
+
+    catalog
+        .buildTable(TBL, variantSchema)
+        .withLocation(baseTableLocation(TBL))
+        .withProperty(TableProperties.FORMAT_VERSION, "3")
+        .create();
+
+    assertThat(catalog.tableExists(TBL)).as("Table should exist").isTrue();
+
+    Table loaded = catalog.loadTable(TBL);
+    assertThat(loaded.schema().asStruct())
+        .as("Variant columns should round-trip through the catalog")
+        .isEqualTo(variantSchema.asStruct());
+    assertThat(TableUtil.formatVersion(loaded))
+        .as("Table with a variant column must be format version 3")
+        .isEqualTo(3);
+  }
+
+  @Test
+  public void testCreateV2TableWithVariantColumnFails() {
+    assumeThat(supportsVariant()).as("Catalog supports the variant 
type").isTrue();
+
+    C catalog = catalog();
+
+    if (requiresNamespaceCreate()) {
+      catalog.createNamespace(TBL.namespace());
+    }
+
+    Schema variantSchema =
+        new Schema(
+            required(1, "id", Types.LongType.get()), optional(2, "data", 
Types.VariantType.get()));
+
+    assertThatThrownBy(
+            () ->
+                catalog
+                    .buildTable(TBL, variantSchema)
+                    .withLocation(baseTableLocation(TBL))
+                    .withProperty(TableProperties.FORMAT_VERSION, "2")
+                    .create())
+        .hasMessageContaining("is not supported until v3");

Review Comment:
   I'm not sure if this is what @laskoviymishka is saying but fundamentally 
this test feels a bit weird to me. Is it even hitting the catalog? the 
validation that's being triggered here is a purely client side validation and 
so I'm not sure what we're really testing from a compatibility angle here. 



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