nssalian commented on code in PR #17500:
URL: https://github.com/apache/iceberg/pull/17500#discussion_r3738515360
##########
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:
To clean up I made it .hasMessageContaining("variant is not supported until
v3") and added the tableExists check so it stays portable across catalogs.
Client-side pre-rejection feels like a separate RESTSessionCatalog change,
happy to file a follow-up if we want it or fold it into this?
##########
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());
Review Comment:
Done. The request schema now goes in with ids 10-18 and I assert an explicit
expected schema with the reassigned ids 1-9.
##########
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())));
Review Comment:
Added the struct_data{v: variant} position. good call.
##########
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();
Review Comment:
I reframed all three variant guards to .as("Only valid when the catalog
supports the variant type").
--
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]