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

fanng pushed a commit to branch iceberg-format
in repository https://gitbox.apache.org/repos/asf/gravitino.git

commit b65ecb90b6a2f64ee43abeff08730f7b0a1638da
Author: fanng <[email protected]>
AuthorDate: Fri Feb 6 12:46:45 2026 +0800

    fix commment
---
 .../main/java/org/apache/gravitino/rel/Table.java  |   1 +
 ...talog.lakehouse.generic.LakehouseTableDelegator |   1 +
 .../generic/TestGenericCatalogOperations.java      | 108 +++++++++++++++++++++
 3 files changed, 110 insertions(+)

diff --git a/api/src/main/java/org/apache/gravitino/rel/Table.java 
b/api/src/main/java/org/apache/gravitino/rel/Table.java
index d9b95c5210..10ca6452c7 100644
--- a/api/src/main/java/org/apache/gravitino/rel/Table.java
+++ b/api/src/main/java/org/apache/gravitino/rel/Table.java
@@ -57,6 +57,7 @@ public interface Table extends Auditable {
    *
    * <ul>
    *   <li>lance
+   *   <li>iceberg
    * </ul>
    */
   String PROPERTY_TABLE_FORMAT = "format";
diff --git 
a/catalogs/catalog-lakehouse-generic/src/main/resources/META-INF/services/org.apache.gravitino.catalog.lakehouse.generic.LakehouseTableDelegator
 
b/catalogs/catalog-lakehouse-generic/src/main/resources/META-INF/services/org.apache.gravitino.catalog.lakehouse.generic.LakehouseTableDelegator
index 352813f4b1..ee05ddc860 100644
--- 
a/catalogs/catalog-lakehouse-generic/src/main/resources/META-INF/services/org.apache.gravitino.catalog.lakehouse.generic.LakehouseTableDelegator
+++ 
b/catalogs/catalog-lakehouse-generic/src/main/resources/META-INF/services/org.apache.gravitino.catalog.lakehouse.generic.LakehouseTableDelegator
@@ -17,3 +17,4 @@
 # under the License.
 #
 org.apache.gravitino.catalog.lakehouse.lance.LanceTableDelegator
+org.apache.gravitino.catalog.lakehouse.iceberg.IcebergTableDelegator
diff --git 
a/catalogs/catalog-lakehouse-generic/src/test/java/org/apache/gravitino/catalog/lakehouse/generic/TestGenericCatalogOperations.java
 
b/catalogs/catalog-lakehouse-generic/src/test/java/org/apache/gravitino/catalog/lakehouse/generic/TestGenericCatalogOperations.java
index 8f61c12182..5d422010ba 100644
--- 
a/catalogs/catalog-lakehouse-generic/src/test/java/org/apache/gravitino/catalog/lakehouse/generic/TestGenericCatalogOperations.java
+++ 
b/catalogs/catalog-lakehouse-generic/src/test/java/org/apache/gravitino/catalog/lakehouse/generic/TestGenericCatalogOperations.java
@@ -38,6 +38,8 @@ import java.io.File;
 import java.io.IOException;
 import java.time.Instant;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
@@ -54,6 +56,7 @@ import org.apache.gravitino.NameIdentifier;
 import org.apache.gravitino.Namespace;
 import org.apache.gravitino.Schema;
 import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.connector.CatalogInfo;
 import org.apache.gravitino.exceptions.NoSuchCatalogException;
 import org.apache.gravitino.exceptions.NoSuchSchemaException;
 import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
@@ -61,6 +64,10 @@ import org.apache.gravitino.meta.AuditInfo;
 import org.apache.gravitino.meta.BaseMetalake;
 import org.apache.gravitino.meta.CatalogEntity;
 import org.apache.gravitino.meta.SchemaVersion;
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.Table;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.types.Types;
 import org.apache.gravitino.storage.IdGenerator;
 import org.apache.gravitino.storage.RandomIdGenerator;
 import org.apache.gravitino.utils.NameIdentifierUtil;
@@ -79,6 +86,7 @@ public class TestGenericCatalogOperations {
   private static EntityStore store;
   private static IdGenerator idGenerator;
   private static GenericCatalogOperations ops;
+  private static GenericCatalog genericCatalog;
 
   @BeforeAll
   public static void setUp() throws IOException, IllegalAccessException {
@@ -137,6 +145,7 @@ public class TestGenericCatalogOperations {
     FieldUtils.writeField(GravitinoEnv.getInstance(), "config", config, true);
 
     ops = new GenericCatalogOperations(store, idGenerator);
+    genericCatalog = new GenericCatalog();
   }
 
   @AfterAll
@@ -230,6 +239,105 @@ public class TestGenericCatalogOperations {
             false));
   }
 
+  @Test
+  public void testCreateExternalIcebergTable() throws Exception {
+    initializeCatalogOps();
+
+    String schemaName = randomSchemaName();
+    NameIdentifier schemaIdent =
+        NameIdentifierUtil.ofSchema(METALAKE_NAME, CATALOG_NAME, schemaName);
+    Map<String, String> schemaProperties =
+        StringIdentifier.newPropertiesWithId(
+            StringIdentifier.fromId(idGenerator.nextId()),
+            Collections.singletonMap(Schema.PROPERTY_LOCATION, 
"/tmp/iceberg_schema"));
+    ops.createSchema(schemaIdent, "schema comment", schemaProperties);
+
+    NameIdentifier tableIdent =
+        NameIdentifierUtil.ofTable(METALAKE_NAME, CATALOG_NAME, schemaName, 
"iceberg_table");
+    Column[] columns = new Column[] {Column.of("id", Types.IntegerType.get(), 
"id column")};
+    Map<String, String> tableProperties = new HashMap<>();
+    tableProperties.put(Table.PROPERTY_TABLE_FORMAT, "iceberg");
+    tableProperties.put(Table.PROPERTY_EXTERNAL, "true");
+    tableProperties.put(Table.PROPERTY_LOCATION, "/tmp/iceberg_table");
+    tableProperties =
+        StringIdentifier.newPropertiesWithId(
+            StringIdentifier.fromId(idGenerator.nextId()), tableProperties);
+
+    Table createdTable =
+        ops.createTable(
+            tableIdent, columns, "table comment", tableProperties, null, null, 
null, null);
+
+    Assertions.assertEquals("iceberg", 
createdTable.properties().get(Table.PROPERTY_TABLE_FORMAT));
+    Assertions.assertEquals("true", 
createdTable.properties().get(Table.PROPERTY_EXTERNAL));
+    Assertions.assertEquals(
+        "/tmp/iceberg_table/", 
createdTable.properties().get(Table.PROPERTY_LOCATION));
+
+    Assertions.assertThrows(UnsupportedOperationException.class, () -> 
ops.purgeTable(tableIdent));
+
+    Assertions.assertThrows(
+        IllegalArgumentException.class,
+        () ->
+            ops.alterTable(tableIdent, 
TableChange.setProperty(Table.PROPERTY_EXTERNAL, "false")));
+    Assertions.assertThrows(
+        IllegalArgumentException.class,
+        () ->
+            ops.alterTable(
+                tableIdent, 
TableChange.setProperty(Table.PROPERTY_TABLE_FORMAT, "lance")));
+
+    Assertions.assertTrue(ops.dropTable(tableIdent));
+  }
+
+  @Test
+  public void testCreateIcebergTableWithoutExternal() throws Exception {
+    initializeCatalogOps();
+
+    String schemaName = randomSchemaName();
+    NameIdentifier schemaIdent =
+        NameIdentifierUtil.ofSchema(METALAKE_NAME, CATALOG_NAME, schemaName);
+    Map<String, String> schemaProperties =
+        StringIdentifier.newPropertiesWithId(
+            StringIdentifier.fromId(idGenerator.nextId()),
+            Collections.singletonMap(Schema.PROPERTY_LOCATION, 
"/tmp/iceberg_schema_2"));
+    ops.createSchema(schemaIdent, "schema comment", schemaProperties);
+
+    NameIdentifier tableIdent =
+        NameIdentifierUtil.ofTable(METALAKE_NAME, CATALOG_NAME, schemaName, 
"iceberg_table_no_ext");
+    Column[] columns = new Column[] {Column.of("id", Types.IntegerType.get(), 
"id column")};
+    Map<String, String> tableProperties = new HashMap<>();
+    tableProperties.put(Table.PROPERTY_TABLE_FORMAT, "iceberg");
+    tableProperties.put(Table.PROPERTY_LOCATION, "/tmp/iceberg_table_2");
+    Map<String, String> tablePropertiesFinal =
+        StringIdentifier.newPropertiesWithId(
+            StringIdentifier.fromId(idGenerator.nextId()), tableProperties);
+
+    Assertions.assertThrows(
+        IllegalArgumentException.class,
+        () ->
+            ops.createTable(
+                tableIdent,
+                columns,
+                "table comment",
+                tablePropertiesFinal,
+                null,
+                null,
+                null,
+                null));
+  }
+
+  private void initializeCatalogOps() {
+    CatalogInfo catalogInfo =
+        new CatalogInfo(
+            idGenerator.nextId(),
+            CATALOG_NAME,
+            Catalog.Type.RELATIONAL,
+            "generic-lakehouse",
+            null,
+            Collections.emptyMap(),
+            
AuditInfo.builder().withCreator("test").withCreateTime(Instant.now()).build(),
+            Namespace.of(METALAKE_NAME));
+    ops.initialize(Collections.emptyMap(), catalogInfo, genericCatalog);
+  }
+
   private String randomSchemaName() {
     return "schema_" + UUID.randomUUID().toString().replace("-", "");
   }

Reply via email to