This is an automated email from the ASF dual-hosted git repository.
pchenxi 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 686921fed7 [#10325] improvement: Fix schema metadata loss in
SchemaOperationDispatcher.alterSchema entity-store update path (#10393)
686921fed7 is described below
commit 686921fed7b6a942c9d211b3b2a614b6b9dc239d
Author: Lucas <[email protected]>
AuthorDate: Wed Apr 1 11:19:00 2026 +0800
[#10325] improvement: Fix schema metadata loss in
SchemaOperationDispatcher.alterSchema entity-store update path (#10393)
<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
Examples:
- "[#123] feat(operator): Support xxx"
- "[#233] fix: Check null before access result in xxx"
- "[MINOR] refactor: Fix typo in variable name"
- "[MINOR] docs: Fix typo in README"
- "[#255] test: Fix flaky test NameOfTheTest"
Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->
### What changes were proposed in this pull request?
- Fixed schema metadata loss during alteration by preserving comment and
properties in `SchemaOperationDispatcher.alterSchema` method
### Why are the changes needed?
Fix: #10325
### Does this PR introduce _any_ user-facing change?
### How was this patch tested?
Added `testAlterSchemaKeepsStoredCommentAndProperties`
and`testAlterSchemaMultipleTimesKeepsMetadata`.
---
.../catalog/SchemaOperationDispatcher.java | 4 ++
.../catalog/TestSchemaOperationDispatcher.java | 47 ++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git
a/core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java
b/core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java
index b61c99e0d7..6883ca4418 100644
---
a/core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java
+++
b/core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java
@@ -274,6 +274,10 @@ public class SchemaOperationDispatcher extends
OperationDispatcher implements Sc
.withId(schemaEntity.id())
.withName(schemaEntity.name())
.withNamespace(ident.namespace())
+ .withComment(alteredSchema.comment())
+ .withProperties(
+ StringIdentifier.newPropertiesWithoutId(
+ alteredSchema.properties()))
.withAuditInfo(
AuditInfo.builder()
.withCreator(schemaEntity.auditInfo().creator())
diff --git
a/core/src/test/java/org/apache/gravitino/catalog/TestSchemaOperationDispatcher.java
b/core/src/test/java/org/apache/gravitino/catalog/TestSchemaOperationDispatcher.java
index f57a8c4038..3b52b3198d 100644
---
a/core/src/test/java/org/apache/gravitino/catalog/TestSchemaOperationDispatcher.java
+++
b/core/src/test/java/org/apache/gravitino/catalog/TestSchemaOperationDispatcher.java
@@ -278,6 +278,53 @@ public class TestSchemaOperationDispatcher extends
TestOperationDispatcher {
Assertions.assertEquals("test", alteredSchema1.auditInfo().lastModifier());
}
+ @Test
+ public void testAlterSchemaKeepsStoredCommentAndProperties() throws
IOException {
+ NameIdentifier schemaIdent = NameIdentifier.of(metalake, catalog,
"schema_preserve_metadata");
+ Map<String, String> props = ImmutableMap.of("k1", "v1", "k2", "v2");
+ dispatcher.createSchema(schemaIdent, "comment", props);
+
+ SchemaChange[] changes =
+ new SchemaChange[] {
+ SchemaChange.setProperty("k3", "v3"),
SchemaChange.removeProperty("k1")
+ };
+ dispatcher.alterSchema(schemaIdent, changes);
+
+ SchemaEntity storedSchema = entityStore.get(schemaIdent, SCHEMA,
SchemaEntity.class);
+ Assertions.assertEquals("comment", storedSchema.comment());
+ Assertions.assertEquals(ImmutableMap.of("k2", "v2", "k3", "v3"),
storedSchema.properties());
+ }
+
+ @Test
+ public void testAlterSchemaMultipleTimesKeepsMetadata() throws IOException {
+ NameIdentifier schemaIdent = NameIdentifier.of(metalake, catalog,
"schema_multiple_alter");
+ Map<String, String> props = ImmutableMap.of("k1", "v1", "k2", "v2");
+ dispatcher.createSchema(schemaIdent, "initial comment", props);
+
+ // First alteration: add a property
+ SchemaChange[] changes1 = new SchemaChange[]
{SchemaChange.setProperty("k3", "v3")};
+ dispatcher.alterSchema(schemaIdent, changes1);
+
+ // Check metadata after first alteration
+ SchemaEntity storedSchema1 = entityStore.get(schemaIdent, SCHEMA,
SchemaEntity.class);
+ Assertions.assertEquals("initial comment", storedSchema1.comment());
+ Assertions.assertEquals(
+ ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"),
storedSchema1.properties());
+
+ // Second alteration: remove a property and add a new one
+ SchemaChange[] changes2 =
+ new SchemaChange[] {
+ SchemaChange.removeProperty("k1"), SchemaChange.setProperty("k4",
"v4")
+ };
+ dispatcher.alterSchema(schemaIdent, changes2);
+
+ // Check metadata after second alteration
+ SchemaEntity storedSchema2 = entityStore.get(schemaIdent, SCHEMA,
SchemaEntity.class);
+ Assertions.assertEquals("initial comment", storedSchema2.comment());
+ Assertions.assertEquals(
+ ImmutableMap.of("k2", "v2", "k3", "v3", "k4", "v4"),
storedSchema2.properties());
+ }
+
@Test
public void testCreateAndDropSchema() throws IOException {
NameIdentifier schemaIdent = NameIdentifier.of(metalake, catalog,
"schema31");