roryqi commented on code in PR #10874:
URL: https://github.com/apache/gravitino/pull/10874#discussion_r3161152704
##########
core/src/test/java/org/apache/gravitino/storage/relational/service/TestSchemaMetaService.java:
##########
@@ -170,6 +177,186 @@ public void testMetaLifeCycleFromCreationToDeletion()
throws IOException {
assertFalse(legacyRecordExistsInDB(schema.id(), Entity.EntityType.SCHEMA));
}
+ @TestTemplate
+ public void testNestedSchemaInsertStoresPhysicalNameAndReturnsLogical()
throws IOException {
+ createAndInsertMakeLake(metalakeName);
+ createAndInsertCatalog(metalakeName, catalogName);
+
+ SchemaMetaService schemaMetaService = SchemaMetaService.getInstance();
+ String logicalName = "teamA:sales:reports";
+ SchemaEntity schema =
+ createSchemaEntity(
+ RandomIdGenerator.INSTANCE.nextId(),
+ NamespaceUtil.ofSchema(metalakeName, catalogName),
+ logicalName,
+ AUDIT_INFO);
+ schemaMetaService.insertSchema(schema, false);
+
+ // Reading back via getSchemaByIdentifier must return the logical name.
+ SchemaEntity loaded =
+ schemaMetaService.getSchemaByIdentifier(
+ NameIdentifierUtil.ofSchema(metalakeName, catalogName,
logicalName));
+ Assertions.assertEquals(logicalName, loaded.name());
+
+ // The raw row stored in the DB must use the physical separator ".".
+ String rawStoredName = readRawSchemaNameFromDb(schema.id());
+ Assertions.assertEquals("teamA.sales.reports", rawStoredName);
+ }
+
+ @TestTemplate
+ public void testFlatSchemaNameStoredAndReturnedUnchanged() throws
IOException {
+ createAndInsertMakeLake(metalakeName);
+ createAndInsertCatalog(metalakeName, catalogName);
+
+ SchemaMetaService schemaMetaService = SchemaMetaService.getInstance();
+ String flatName = "flat_schema";
+ SchemaEntity schema =
+ createSchemaEntity(
+ RandomIdGenerator.INSTANCE.nextId(),
+ NamespaceUtil.ofSchema(metalakeName, catalogName),
+ flatName,
+ AUDIT_INFO);
+ schemaMetaService.insertSchema(schema, false);
+
+ SchemaEntity loaded =
+ schemaMetaService.getSchemaByIdentifier(
+ NameIdentifierUtil.ofSchema(metalakeName, catalogName, flatName));
+ Assertions.assertEquals(flatName, loaded.name());
+
+ // Flat name: raw DB value must equal the name as-is.
+ Assertions.assertEquals(flatName, readRawSchemaNameFromDb(schema.id()));
+ }
+
+ @TestTemplate
+ public void testListSchemasReturnsLogicalNames() throws IOException {
+ createAndInsertMakeLake(metalakeName);
+ createAndInsertCatalog(metalakeName, catalogName);
+
+ SchemaMetaService schemaMetaService = SchemaMetaService.getInstance();
+
+ SchemaEntity flat =
+ createSchemaEntity(
+ RandomIdGenerator.INSTANCE.nextId(),
+ NamespaceUtil.ofSchema(metalakeName, catalogName),
+ "flat",
+ AUDIT_INFO);
+ SchemaEntity nested2 =
+ createSchemaEntity(
+ RandomIdGenerator.INSTANCE.nextId(),
+ NamespaceUtil.ofSchema(metalakeName, catalogName),
+ "A:B",
+ AUDIT_INFO);
+ SchemaEntity nested3 =
+ createSchemaEntity(
+ RandomIdGenerator.INSTANCE.nextId(),
+ NamespaceUtil.ofSchema(metalakeName, catalogName),
+ "A:B:C",
+ AUDIT_INFO);
+ schemaMetaService.insertSchema(flat, false);
+ schemaMetaService.insertSchema(nested2, false);
+ schemaMetaService.insertSchema(nested3, false);
+
+ List<SchemaEntity> listed =
+
schemaMetaService.listSchemasByNamespace(NamespaceUtil.ofSchema(metalakeName,
catalogName));
+
+ List<String> names =
+
listed.stream().map(SchemaEntity::name).collect(java.util.stream.Collectors.toList());
+ Assertions.assertTrue(names.contains("flat"), "flat name must be present");
Review Comment:
Accepted.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]