Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#5719] fix(paimon): Store the schema comment when creating a Paimon schema (#14573)

ZIHAN DAI61f58ee54e63
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);
+ }
}