From 47782309ce47e708007b320c4a0ae11c18b3d3d4 Mon Sep 17 00:00:00 2001 From: zy-kkk Date: Tue, 14 Jan 2025 10:54:41 +0800 Subject: [PATCH 1/2] [fix](external catalog) Persisting the External Catalog comment field --- .../java/org/apache/doris/datasource/ExternalCatalog.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java index 633113f27cfebe..b1eb8ab6afe0f3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java @@ -139,6 +139,9 @@ public abstract class ExternalCatalog // to tableAutoAnalyzePolicy @SerializedName(value = "taap") protected Map, String> tableAutoAnalyzePolicy = Maps.newHashMap(); + @SerializedName(value = "comment") + private String comment; + // db name does not contains "default_cluster" protected Map dbNameToId = Maps.newConcurrentMap(); private boolean objectCreated = false; @@ -147,7 +150,6 @@ public abstract class ExternalCatalog protected TransactionManager transactionManager; private ExternalSchemaCache schemaCache; - private String comment; // A cached and being converted properties for external catalog. // generated from catalog properties. private byte[] propLock = new byte[0]; From 769315ac547aada8694d525d089d878c0f2af568 Mon Sep 17 00:00:00 2001 From: zy-kkk Date: Tue, 14 Jan 2025 16:20:44 +0800 Subject: [PATCH 2/2] add ut --- .../doris/datasource/ExternalCatalogTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fe/fe-core/src/test/java/org/apache/doris/datasource/ExternalCatalogTest.java b/fe/fe-core/src/test/java/org/apache/doris/datasource/ExternalCatalogTest.java index f8e72c366b55f7..67d1e2d7ab4f31 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/datasource/ExternalCatalogTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/datasource/ExternalCatalogTest.java @@ -276,4 +276,37 @@ public void testSerialization() throws Exception { dis.close(); file.delete(); } + + @Test + public void testSerializationWithComment() throws Exception { + MetaContext metaContext = new MetaContext(); + metaContext.setMetaVersion(FeMetaVersion.VERSION_CURRENT); + metaContext.setThreadLocalInfo(); + + // 1. Write objects to file + File file = new File("./external_catalog_with_comment_test.dat"); + file.createNewFile(); + DataOutputStream dos = new DataOutputStream(Files.newOutputStream(file.toPath())); + + TestExternalCatalog ctl = (TestExternalCatalog) mgr.getCatalog("test1"); + String testComment = "This is a test comment for serialization"; + ctl.setComment(testComment); // Set a custom comment value + ctl.write(dos); + dos.flush(); + dos.close(); + + // 2. Read objects from file + DataInputStream dis = new DataInputStream(Files.newInputStream(file.toPath())); + + TestExternalCatalog ctl2 = (TestExternalCatalog) ExternalCatalog.read(dis); + Configuration conf = ctl2.getConfiguration(); + Assertions.assertNotNull(conf); + + // Verify the comment is properly serialized and deserialized + Assertions.assertEquals(testComment, ctl2.getComment()); + + // 3. delete files + dis.close(); + file.delete(); + } }