You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by am...@apache.org on 2026/08/07 21:39:06 UTC

(iceberg) branch main updated: Core, OpenAPI: Add RCK coverage for variant columns (#17500)

This is an automated email from the ASF dual-hosted git repository.

amogh-jahagirdar pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/main by this push:
     new 14a9b215c3 Core, OpenAPI: Add RCK coverage for variant columns (#17500)
14a9b215c3 is described below

commit 14a9b215c3fa9e4604f7fd8345c55bd3808b4aef
Author: Neelesh Salian <ns...@users.noreply.github.com>
AuthorDate: Fri Aug 7 14:38:59 2026 -0700

    Core, OpenAPI: Add RCK coverage for variant columns (#17500)
---
 .../org/apache/iceberg/catalog/CatalogTests.java   | 127 +++++++++++++++++++++
 .../org/apache/iceberg/rest/TestRESTCatalog.java   |   5 +
 open-api/README.md                                 |  11 +-
 .../rest/RESTCompatibilityKitCatalogTests.java     |   6 +
 .../iceberg/rest/RESTCompatibilityKitSuite.java    |   1 +
 5 files changed, 146 insertions(+), 4 deletions(-)

diff --git a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
index 6c6949ce42..ff40527ebe 100644
--- a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
+++ b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
@@ -18,6 +18,7 @@
  */
 package org.apache.iceberg.catalog;
 
+import static org.apache.iceberg.types.Types.NestedField.optional;
 import static org.apache.iceberg.types.Types.NestedField.required;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -203,6 +204,10 @@ public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
     return false;
   }
 
+  protected boolean supportsVariant() {
+    return false;
+  }
+
   protected String baseTableLocation(TableIdentifier identifier) {
     return BASE_TABLE_LOCATION + "/" + identifier.namespace() + "/" + identifier.name();
   }
@@ -966,6 +971,128 @@ public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
         .containsAll(properties.entrySet());
   }
 
+  @Test
+  public void testCreateTableWithVariantColumn() {
+    assumeThat(supportsVariant())
+        .as("Only valid when the 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 requestedSchema =
+        new Schema(
+            required(10, "id", Types.LongType.get()),
+            optional(11, "data", Types.VariantType.get()),
+            optional(12, "list_data", Types.ListType.ofOptional(13, Types.VariantType.get())),
+            optional(
+                14,
+                "map_data",
+                Types.MapType.ofOptional(15, 16, Types.StringType.get(), Types.VariantType.get())),
+            optional(
+                17,
+                "struct_data",
+                Types.StructType.of(optional(18, "v", Types.VariantType.get()))));
+
+    // This is the actual schema for the table, with column IDs reassigned
+    Schema expectedSchema =
+        new Schema(
+            required(1, "id", Types.LongType.get()),
+            optional(2, "data", Types.VariantType.get()),
+            optional(3, "list_data", Types.ListType.ofOptional(6, Types.VariantType.get())),
+            optional(
+                4,
+                "map_data",
+                Types.MapType.ofOptional(7, 8, Types.StringType.get(), Types.VariantType.get())),
+            optional(
+                5, "struct_data", Types.StructType.of(optional(9, "v", Types.VariantType.get()))));
+
+    catalog
+        .buildTable(TBL, requestedSchema)
+        .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(expectedSchema.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("Only valid when the 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("variant is not supported until v3");
+
+    assertThat(catalog.tableExists(TBL)).as("Table should not have been created").isFalse();
+  }
+
+  @Test
+  public void testAddVariantColumnToExistingTable() {
+    assumeThat(supportsVariant())
+        .as("Only valid when the catalog supports the variant type")
+        .isTrue();
+
+    C catalog = catalog();
+
+    if (requiresNamespaceCreate()) {
+      catalog.createNamespace(TBL.namespace());
+    }
+
+    Schema initialSchema = new Schema(required(1, "id", Types.LongType.get()));
+
+    Table table =
+        catalog
+            .buildTable(TBL, initialSchema)
+            .withLocation(baseTableLocation(TBL))
+            .withProperty(TableProperties.FORMAT_VERSION, "3")
+            .create();
+
+    table.updateSchema().addColumn("data", Types.VariantType.get()).commit();
+
+    Schema expectedSchema =
+        new Schema(
+            required(1, "id", Types.LongType.get()), optional(2, "data", Types.VariantType.get()));
+
+    Table loaded = catalog.loadTable(TBL);
+    assertThat(loaded.schema().asStruct())
+        .as("Added variant column should round-trip through the catalog")
+        .isEqualTo(expectedSchema.asStruct());
+    assertThat(TableUtil.formatVersion(loaded))
+        .as("Table with a variant column must be format version 3")
+        .isEqualTo(3);
+  }
+
   @Test
   public void testLoadTableWithNonExistingNamespace() {
     TableIdentifier ident = TableIdentifier.of("non-existing", "tbl");
diff --git a/core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java b/core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
index d2d45c6173..cb100437e4 100644
--- a/core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
+++ b/core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
@@ -433,6 +433,11 @@ public class TestRESTCatalog extends CatalogTests<RESTCatalog> {
     return false;
   }
 
+  @Override
+  protected boolean supportsVariant() {
+    return true;
+  }
+
   /* RESTCatalog specific tests */
 
   @Test
diff --git a/open-api/README.md b/open-api/README.md
index cf13df60f7..6c66da3d54 100644
--- a/open-api/README.md
+++ b/open-api/README.md
@@ -82,10 +82,13 @@ rck.credential=<oauth_key>:<oauth_secret>             ## -> credential=<oauth_ke
 Some test behaviors are configurable depending on the catalog implementations.  Not all behaviors
 are strictly defined by the REST Specification.  The following are currently configurable:
 
-| config                        | default |
-|-------------------------------|---------|
-| rck.requires-namespace-create | true    |
-| rck.supports-serverside-retry | true    |
+| config                           | default |
+|----------------------------------|---------|
+| rck.requires-namespace-create    | true    |
+| rck.supports-serverside-retry    | true    |
+| rck.overrides-requested-location | false   |
+| rck.supports-names-with-dot      | false   |
+| rck.supports-variant             | false   |
 
 
 ## Running Compatibility Tests
diff --git a/open-api/src/test/java/org/apache/iceberg/rest/RESTCompatibilityKitCatalogTests.java b/open-api/src/test/java/org/apache/iceberg/rest/RESTCompatibilityKitCatalogTests.java
index cbf752e484..611a6a20da 100644
--- a/open-api/src/test/java/org/apache/iceberg/rest/RESTCompatibilityKitCatalogTests.java
+++ b/open-api/src/test/java/org/apache/iceberg/rest/RESTCompatibilityKitCatalogTests.java
@@ -109,6 +109,12 @@ public class RESTCompatibilityKitCatalogTests extends CatalogTests<RESTCatalog>
     return false;
   }
 
+  @Override
+  protected boolean supportsVariant() {
+    return PropertyUtil.propertyAsBoolean(
+        restCatalog.properties(), RESTCompatibilityKitSuite.RCK_SUPPORTS_VARIANT, false);
+  }
+
   @Disabled("RESTServerExtension isn’t configurable per test")
   @Test
   public void createTableInUniqueLocation() {
diff --git a/open-api/src/test/java/org/apache/iceberg/rest/RESTCompatibilityKitSuite.java b/open-api/src/test/java/org/apache/iceberg/rest/RESTCompatibilityKitSuite.java
index a153d48b8c..c2d11669e1 100644
--- a/open-api/src/test/java/org/apache/iceberg/rest/RESTCompatibilityKitSuite.java
+++ b/open-api/src/test/java/org/apache/iceberg/rest/RESTCompatibilityKitSuite.java
@@ -41,6 +41,7 @@ public class RESTCompatibilityKitSuite {
   static final String RCK_SUPPORTS_SERVERSIDE_RETRY = "rck.supports-serverside-retry";
   static final String RCK_OVERRIDES_REQUESTED_LOCATION = "rck.overrides-requested-location";
   static final String RCK_SUPPORTS_NAMES_WITH_DOT = "rck.supports-names-with-dot";
+  static final String RCK_SUPPORTS_VARIANT = "rck.supports-variant";
 
   protected RESTCompatibilityKitSuite() {}
 }