branch-2.1: [fix](external catalog) Persisting the External Catalog comment field… (#47569)
cherry-pick (#46946)
This commit is contained in:
@ -134,6 +134,9 @@ public abstract class ExternalCatalog
|
||||
protected Map<Long, ExternalDatabase<? extends ExternalTable>> idToDb = Maps.newConcurrentMap();
|
||||
@SerializedName(value = "lastUpdateTime")
|
||||
protected long lastUpdateTime;
|
||||
@SerializedName(value = "comment")
|
||||
private String comment;
|
||||
|
||||
// db name does not contains "default_cluster"
|
||||
protected Map<String, Long> dbNameToId = Maps.newConcurrentMap();
|
||||
private boolean objectCreated = false;
|
||||
@ -142,7 +145,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];
|
||||
|
||||
@ -282,4 +282,38 @@ public class ExternalCatalogTest extends TestWithFeService {
|
||||
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()));
|
||||
|
||||
String json = Text.readString(dis);
|
||||
TestExternalCatalog ctl2 = GsonUtils.GSON.fromJson(json, TestExternalCatalog.class);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user