This is an automated email from the ASF dual-hosted git repository.
jerryshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 61f58ee54e [#5719] fix(paimon): Store the schema comment when creating
a Paimon schema (#14573)
61f58ee54e is described below
commit 61f58ee54e634b72c5521184893d132103fabb3c
Author: ZIHAN DAI <[email protected]>
AuthorDate: Tue Nov 17 22:16:19 2026 +1100
[#5719] fix(paimon): Store the schema comment when creating a Paimon schema
(#14573)
### What changes were proposed in this pull request?
`PaimonSchema.toPaimonProperties()` now returns a copy of the schema
properties with the schema comment added under the reserved `comment`
property. `PaimonCatalogOperations.createSchema` passes this map to
Paimon's `createDatabase`, so the comment is written to the Paimon
database.
`comment` is the key Paimon defines for database comments
(`Catalog.COMMENT_PROP`), and it is the key
`PaimonSchema.fromPaimonProperties` already reads in `loadSchema`.
`IcebergSchema.toCreateRequest` stores the comment of an Iceberg
namespace the same way.
### Why are the changes needed?
A Paimon schema created with a comment loses the comment. The create
response still shows it, because that response is built from the
request. But `createSchema` passed only the user properties to Paimon,
so the comment was never stored, and every later load returns `comment:
null`. #5719 shows this on the JDBC backend.
The Paimon catalog docs say that only the filesystem backend cannot
store schema comments, but the code dropped them on every backend. This
change makes the code match the docs. The catalog already declares
`comment` as a reserved, hidden schema property, and `loadSchema`
already reads it from there.
Reproduction on the 1.3.1 Docker image (`apache/gravitino:1.3.1`), with
a Paimon catalog using `catalog-backend=jdbc` on PostgreSQL 16:
```
POST /api/metalakes/repro_ml/catalogs/paimon_jdbc/schemas
{"name":"sales","comment":"Sales data owned by the finance
team","properties":{"owner-team":"finance"}}
-> code=0 name=sales comment='Sales data owned by the finance team'
properties={'owner-team': 'finance'}
GET /api/metalakes/repro_ml/catalogs/paimon_jdbc/schemas/sales
-> code=0 name=sales comment=None properties={'owner-team': 'finance',
'location': 'file:/tmp/paimon_wh/sales.db'}
SELECT property_key, property_value FROM paimon_database_properties WHERE
database_name = 'sales';
exists | true
gravitino.identifier | gravitino.v1.uid3161155087733269982
location | file:/tmp/paimon_wh/sales.db
owner-team | finance
```
I then compiled this change into
`gravitino-catalog-lakehouse-paimon-1.3.1.jar` and repeated the same
steps on the same image. `PaimonSchema.java` is identical on 1.3.1 and
`main`.
```
GET /api/metalakes/repro_ml/catalogs/paimon_jdbc/schemas/sales
-> code=0 name=sales comment='Sales data owned by the finance team'
properties={'owner-team': 'finance', 'location': 'file:/tmp/paimon_wh/sales.db'}
SELECT property_key, property_value FROM paimon_database_properties WHERE
database_name = 'sales';
comment | Sales data owned by the finance team
exists | true
gravitino.identifier | gravitino.v1.uid3969426464095332289
location | file:/tmp/paimon_wh/sales.db
owner-team | finance
```
Fixes #5719
### Does this PR introduce _any_ user-facing change?
Yes. On backends that store database properties, a schema comment is now
persisted and returned when the schema is loaded. This was checked on
the JDBC backend. Paimon's `HiveCatalog` maps the same `comment`
property to the Hive database description, but I did not run this change
against a Hive metastore.
The filesystem backend behaves as before: Paimon logs that it cannot
store database properties and discards them, as the docs already say.
`comment` stays hidden from the returned schema properties. There are no
API or property key changes.
### How was this patch tested?
- The new test `TestPaimonSchema#testLoadSchemaCommentWithJdbcBackend`
creates one schema with a comment and one without on a JDBC backend
(in-memory H2), then loads both back. Without the change, it fails with
`expected: <comment> but was: <null>`.
- `./gradlew :catalogs:catalog-lakehouse-paimon:test -PskipITs`, run
with `--tests` for `TestPaimonSchema`, `TestPaimonCatalog`,
`TestGravitinoPaimonTable`, `TestPaimonCatalogPropertiesMetadata` and
`ops.TestPaimonCatalogOps`: 47 tests, 0 failures.
- `./gradlew :catalogs:catalog-lakehouse-paimon:spotlessCheck
:catalogs:catalog-lakehouse-paimon:javadoc` passes.
- I ran the manual check on the 1.3.1 image shown above. On the same
patched server, I also checked two other cases:
- A filesystem-backend catalog still creates a schema with a comment,
and loading it returns no comment, as before.
- A JDBC schema created without a comment loads with `comment=None` and
has no `comment` row in the database.
- I left the Paimon integration tests (`CatalogPaimon*IT`) to CI.
---
.../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);
+ }
}