mchades commented on code in PR #5186:
URL: https://github.com/apache/gravitino/pull/5186#discussion_r1814558945
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/MetadataObjectService.java:
##########
@@ -69,101 +70,130 @@ public static long getMetadataObjectId(
return
FilesetMetaService.getInstance().getFilesetIdBySchemaIdAndName(schemaId,
names.get(2));
} else if (type == MetadataObject.Type.TOPIC) {
return
TopicMetaService.getInstance().getTopicIdBySchemaIdAndName(schemaId,
names.get(2));
- } else if (type == MetadataObject.Type.TABLE) {
- return
TableMetaService.getInstance().getTableIdBySchemaIdAndName(schemaId,
names.get(2));
}
- throw new IllegalArgumentException(String.format("Doesn't support the type
%s", type));
- }
-
- // Metadata object may be null because the metadata object can be deleted
asynchronously.
- @Nullable
- public static String getMetadataObjectFullName(String type, long
metadataObjectId) {
- MetadataObject.Type metadatatype = MetadataObject.Type.valueOf(type);
- if (metadatatype == MetadataObject.Type.METALAKE) {
- MetalakePO metalakePO =
MetalakeMetaService.getInstance().getMetalakePOById(metadataObjectId);
- if (metalakePO == null) {
- return null;
- }
-
- return metalakePO.getMetalakeName();
- }
-
- if (metadatatype == MetadataObject.Type.CATALOG) {
- return getCatalogFullName(metadataObjectId);
- }
-
- if (metadatatype == MetadataObject.Type.SCHEMA) {
- return getSchemaFullName(metadataObjectId);
- }
-
- if (metadatatype == MetadataObject.Type.TABLE) {
- TablePO tablePO =
TableMetaService.getInstance().getTablePOById(metadataObjectId);
- if (tablePO == null) {
- return null;
- }
-
- String schemaName = getSchemaFullName(tablePO.getSchemaId());
- if (schemaName == null) {
- return null;
- }
-
- return DOT_JOINER.join(schemaName, tablePO.getTableName());
- }
-
- if (metadatatype == MetadataObject.Type.TOPIC) {
- TopicPO topicPO =
TopicMetaService.getInstance().getTopicPOById(metadataObjectId);
- if (topicPO == null) {
- return null;
- }
-
- String schemaName = getSchemaFullName(topicPO.getSchemaId());
- if (schemaName == null) {
- return null;
- }
-
- return DOT_JOINER.join(schemaName, topicPO.getTopicName());
+ long tableId =
+ TableMetaService.getInstance().getTableIdBySchemaIdAndName(schemaId,
names.get(2));
+ if (type == MetadataObject.Type.TABLE) {
+ return tableId;
}
- if (metadatatype == MetadataObject.Type.FILESET) {
- FilesetPO filesetPO =
FilesetMetaService.getInstance().getFilesetPOById(metadataObjectId);
- if (filesetPO == null) {
- return null;
- }
-
- String schemaName = getSchemaFullName(filesetPO.getSchemaId());
- if (schemaName == null) {
- return null;
- }
-
- return DOT_JOINER.join(schemaName, filesetPO.getFilesetName());
+ if (type == MetadataObject.Type.COLUMN) {
+ return TableColumnMetaService.getInstance()
+ .getColumnIdByTableIdAndName(tableId, names.get(3));
}
- throw new IllegalArgumentException(String.format("Doesn't support the type
%s", metadatatype));
- }
-
- @Nullable
- private static String getCatalogFullName(Long entityId) {
- CatalogPO catalogPO =
CatalogMetaService.getInstance().getCatalogPOById(entityId);
- if (catalogPO == null) {
- return null;
- }
- return catalogPO.getCatalogName();
+ throw new IllegalArgumentException(String.format("Doesn't support the type
%s", type));
}
+ // Metadata object may be null because the metadata object can be deleted
asynchronously.
@Nullable
- private static String getSchemaFullName(Long entityId) {
- SchemaPO schemaPO =
SchemaMetaService.getInstance().getSchemaPOById(entityId);
-
- if (schemaPO == null) {
- return null;
- }
-
- String catalogName = getCatalogFullName(schemaPO.getCatalogId());
- if (catalogName == null) {
- return null;
- }
+ public static String getMetadataObjectFullName(String type, long
metadataObjectId) {
+ MetadataObject.Type metadataType = MetadataObject.Type.valueOf(type);
+ String fullName = null;
+ long objectId = metadataObjectId;
+
+ do {
+ switch (metadataType) {
+ case METALAKE:
+ MetalakePO metalakePO =
MetalakeMetaService.getInstance().getMetalakePOById(objectId);
+ if (metalakePO != null) {
+ fullName = metalakePO.getMetalakeName();
+ metadataType = null;
+ } else {
+ return null;
+ }
+ break;
+
+ case CATALOG:
+ CatalogPO catalogPO =
CatalogMetaService.getInstance().getCatalogPOById(objectId);
+ if (catalogPO != null) {
+ fullName =
+ fullName != null
+ ? DOT_JOINER.join(catalogPO.getCatalogName(), fullName)
+ : catalogPO.getCatalogName();
+ metadataType = null;
Review Comment:
Don't change to `MetadataObject.Type.METALAKE` to obtain the metalake name?
--
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]