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

diqiu50 pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new feb9684e31 [Cherry-pick to branch-2.0] [#5719] fix(paimon): Store the 
schema comment when creating a Paimon schema (#14573) (#15075)
feb9684e31 is described below

commit feb9684e31b3b19042cc5efc21b844751ffcdf67
Author: Yuhui <[email protected]>
AuthorDate: Thu Nov 19 14:23:30 2026 +0800

    [Cherry-pick to branch-2.0] [#5719] fix(paimon): Store the schema comment 
when creating a Paimon schema (#14573) (#15075)
    
    **Cherry-pick Information:**
    - Original commit: 61f58ee54e634b72c5521184893d132103fabb3c
    - Target branch: `branch-2.0`
    - Status: ✅ Clean cherry-pick (no conflicts)
    
    Co-authored-by: ZIHAN DAI <[email protected]>
---
 .../catalog/lakehouse/paimon/PaimonSchema.java     | 13 ++++-
 .../catalog/lakehouse/paimon/TestPaimonSchema.java | 56 ++++++++++++++++++++++
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git 
a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonSchema.java
 
b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonSchema.java
index 40061fcfb0..ac823e1d13 100644
--- 
a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonSchema.java
+++ 
b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonSchema.java
@@ -20,6 +20,7 @@ package org.apache.gravitino.catalog.lakehouse.paimon;
 
 import static org.apache.gravitino.meta.AuditInfo.EMPTY;
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
 import lombok.ToString;
@@ -36,12 +37,20 @@ public class PaimonSchema extends BaseSchema {
   private PaimonSchema() {}
 
   /**
-   * Converts {@link PaimonSchema} instance to inner schema.
+   * Converts {@link PaimonSchema} instance to inner schema. The schema 
comment is stored under the
+   * {@link PaimonSchemaPropertiesMetadata#COMMENT} property, where Paimon 
keeps database comments.
    *
    * @return The converted inner schema.
    */
   public Map<String, String> toPaimonProperties() {
-    return properties;
+    Map<String, String> paimonProperties = new HashMap<>();
+    if (properties != null) {
+      paimonProperties.putAll(properties);
+    }
+    if (comment != null) {
+      paimonProperties.put(PaimonSchemaPropertiesMetadata.COMMENT, comment);
+    }
+    return paimonProperties;
   }
 
   /**
diff --git 
a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestPaimonSchema.java
 
b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestPaimonSchema.java
index bc9a15ec69..07bf4981d1 100644
--- 
a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestPaimonSchema.java
+++ 
b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestPaimonSchema.java
@@ -59,11 +59,43 @@ public class TestPaimonSchema {
     try {
       FileUtils.deleteDirectory(
           new File(System.getProperty("java.io.tmpdir") + 
"/paimon_catalog_warehouse"));
+      FileUtils.deleteDirectory(
+          new File(System.getProperty("java.io.tmpdir") + 
"/paimon_jdbc_catalog_warehouse"));
     } catch (IOException e) {
       // Ignore
     }
   }
 
+  @Test
+  public void testLoadSchemaCommentWithJdbcBackend() {
+    PaimonCatalog paimonCatalog = 
initJdbcPaimonCatalog("testLoadSchemaCommentWithJdbcBackend");
+    PaimonCatalogOperations paimonCatalogOperations = 
(PaimonCatalogOperations) paimonCatalog.ops();
+
+    NameIdentifier ident =
+        NameIdentifier.of(META_LAKE_NAME, paimonCatalog.name(), 
"test_paimon_schema_comment");
+    Map<String, String> properties = Maps.newHashMap();
+    properties.put("key1", "val1");
+
+    paimonCatalogOperations.createSchema(ident, COMMENT_VALUE, properties);
+    
Assertions.assertFalse(properties.containsKey(PaimonSchemaPropertiesMetadata.COMMENT));
+
+    Schema loadedSchema = paimonCatalogOperations.loadSchema(ident);
+    Assertions.assertEquals(COMMENT_VALUE, loadedSchema.comment());
+    Assertions.assertEquals("val1", loadedSchema.properties().get("key1"));
+
+    NameIdentifier noCommentIdent =
+        NameIdentifier.of(META_LAKE_NAME, paimonCatalog.name(), 
"test_paimon_schema_no_comment");
+    paimonCatalogOperations.createSchema(noCommentIdent, null, 
Maps.newHashMap());
+    Schema noCommentSchema = 
paimonCatalogOperations.loadSchema(noCommentIdent);
+    Assertions.assertNull(noCommentSchema.comment());
+    Assertions.assertFalse(
+        
noCommentSchema.properties().containsKey(PaimonSchemaPropertiesMetadata.COMMENT));
+
+    // clean up
+    cleanUp(paimonCatalogOperations, ident);
+    cleanUp(paimonCatalogOperations, noCommentIdent);
+  }
+
   @Test
   public void testCreatePaimonSchema() {
     PaimonCatalog paimonCatalog = initPaimonCatalog("testCreatePaimonSchema");
@@ -191,4 +223,28 @@ public class TestPaimonSchema {
             File.separator, System.getProperty("java.io.tmpdir"), 
"paimon_catalog_warehouse"));
     return new PaimonCatalog().withCatalogConf(conf).withCatalogEntity(entity);
   }
+
+  private PaimonCatalog initJdbcPaimonCatalog(String name) {
+    CatalogEntity entity =
+        CatalogEntity.builder()
+            .withId(1L)
+            .withName(name)
+            .withNamespace(Namespace.of(META_LAKE_NAME))
+            .withType(PaimonCatalog.Type.RELATIONAL)
+            .withProvider("lakehouse-paimon")
+            .withAuditInfo(AUDIT_INFO)
+            .build();
+
+    Map<String, String> conf = Maps.newHashMap();
+    conf.put(PaimonCatalogPropertiesMetadata.GRAVITINO_CATALOG_BACKEND, 
"jdbc");
+    conf.put(PaimonCatalogPropertiesMetadata.URI, "jdbc:h2:mem:" + name + 
";DB_CLOSE_DELAY=-1");
+    conf.put(PaimonCatalogPropertiesMetadata.GRAVITINO_JDBC_DRIVER, 
"org.h2.Driver");
+    conf.put(PaimonCatalogPropertiesMetadata.GRAVITINO_JDBC_USER, "user");
+    conf.put(PaimonCatalogPropertiesMetadata.GRAVITINO_JDBC_PASSWORD, 
"password");
+    conf.put(
+        PaimonCatalogPropertiesMetadata.WAREHOUSE,
+        String.join(
+            File.separator, System.getProperty("java.io.tmpdir"), 
"paimon_jdbc_catalog_warehouse"));
+    return new PaimonCatalog().withCatalogConf(conf).withCatalogEntity(entity);
+  }
 }

Reply via email to