unknowntpo commented on code in PR #6601:
URL: https://github.com/apache/gravitino/pull/6601#discussion_r1987080538

##########
core/src/main/java/org/apache/gravitino/storage/relational/service/MetadataObjectService.java:
##########
@@ -214,4 +235,412 @@ public static String getMetadataObjectFullName(String 
type, long metadataObjectI
 
     return fullName;
   }
+
+  /**
+   * Retrieves a map of Metalake object IDs to their full names.
+   *
+   * @param ids A list of Metalake object IDs to fetch names for.
+   * @return A Map where the key is the Metalake ID and the value is the 
Metalake full name. The map
+   *     may contain null values for the names if its parent object is 
deleted. Returns an empty map
+   *     if no Metalake objects are found for the given IDs. {@code @example} 
value of metalake full
+   *     name: "metalake1.catalog1.schema1.table1"
+   */
+  public static Map<Long, String> getMetalakeObjectFullNames(List<Long> ids) {
+    List<MetalakePO> metalakePOs =
+        SessionUtils.getWithoutCommit(
+            MetalakeMetaMapper.class, mapper -> 
mapper.listMetalakePOsByMetalakeIds(ids));
+
+    if (metalakePOs == null || metalakePOs.isEmpty()) {
+      return new HashMap<>();
+    }
+
+    HashMap<Long, String> metalakeIdAndNameMap = new HashMap<>();
+
+    metalakePOs.forEach(
+        metalakePO -> {
+          if (metalakePO.getMetalakeId() == null) {
+            metalakeIdAndNameMap.put(metalakePO.getMetalakeId(), null);
+            return;
+          }
+          metalakeIdAndNameMap.put(metalakePO.getMetalakeId(), 
metalakePO.getMetalakeName());
+        });
+
+    return metalakeIdAndNameMap;
+  }
+
+  /**
+   * Retrieves a map of Fileset object IDs to their full names.
+   *
+   * @param ids A list of Fileset object IDs to fetch names for.
+   * @return A Map where the key is the Fileset ID and the value is the 
Fileset full name. The map
+   *     may contain null values for the names if its parent object is 
deleted. Returns an empty map
+   *     if no Fileset objects are found for the given IDs. {@code @example} 
value of fileset full
+   *     name: "catalog1.schema1.fileset1"
+   */
+  public static Map<Long, String> getFilesetObjectFullNames(List<Long> ids) {
+    List<FilesetPO> filesetPOs =
+        SessionUtils.getWithoutCommit(
+            FilesetMetaMapper.class, mapper -> 
mapper.listFilesetPOsByFilesetIds(ids));
+
+    if (filesetPOs == null || filesetPOs.isEmpty()) {
+      return new HashMap<>();
+    }
+
+    List<Long> catalogIds =
+        
filesetPOs.stream().map(FilesetPO::getCatalogId).collect(Collectors.toList());
+    List<Long> schemaIds =
+        
filesetPOs.stream().map(FilesetPO::getSchemaId).collect(Collectors.toList());
+
+    Map<Long, String> catalogIdAndNameMap = getCatalogIdAndNameMap(catalogIds);
+    Map<Long, String> schemaIdAndNameMap = getSchemaIdAndNameMap(schemaIds);
+
+    HashMap<Long, String> filesetIdAndNameMap = new HashMap<>();
+
+    filesetPOs.forEach(
+        filesetPO -> {
+          // since the catalog or schema can be deleted, we need to check the 
null value,
+          // and when catalog or schema is deleted, we will set fullName of 
filesetPO to
+          // null
+          String catalogName = 
catalogIdAndNameMap.getOrDefault(filesetPO.getCatalogId(), null);
+          if (catalogName == null) {
+            LOG.warn("The catalog of fileset {} may be deleted", 
filesetPO.getFilesetId());
+            filesetIdAndNameMap.put(filesetPO.getFilesetId(), null);
+            return;
+          }
+
+          String schemaName = 
schemaIdAndNameMap.getOrDefault(filesetPO.getSchemaId(), null);
+          if (schemaName == null) {
+            LOG.warn("The schema of fileset {} may be deleted", 
filesetPO.getFilesetId());
+            filesetIdAndNameMap.put(filesetPO.getFilesetId(), null);
+            return;
+          }
+
+          String fullName = DOT_JOINER.join(catalogName, schemaName, 
filesetPO.getFilesetName());
+          filesetIdAndNameMap.put(filesetPO.getFilesetId(), fullName);
+        });
+
+    return filesetIdAndNameMap;
+  }
+
+  /**
+   * Retrieves a map of Model object IDs to their full names.
+   *
+   * @param ids A list of Model object IDs to fetch names for.
+   * @return A Map where the key is the Model ID and the value is the Model 
full name. The map may
+   *     contain null values for the names if its parent object is deleted. 
Returns an empty map if
+   *     no Model objects are found for the given IDs. {@code @example} value 
of model full name:
+   *     "catalog1.schema1.model1"
+   */
+  public static Map<Long, String> getModelObjectFullNames(List<Long> ids) {
+    List<ModelPO> modelPOs =
+        SessionUtils.getWithoutCommit(
+            ModelMetaMapper.class, mapper -> 
mapper.listModelPOsByModelIds(ids));
+
+    if (modelPOs == null || modelPOs.isEmpty()) {
+      return new HashMap<>();
+    }
+
+    List<Long> catalogIds =
+        
modelPOs.stream().map(ModelPO::getCatalogId).collect(Collectors.toList());
+    List<Long> schemaIds = 
modelPOs.stream().map(ModelPO::getSchemaId).collect(Collectors.toList());
+
+    Map<Long, String> catalogIdAndNameMap = getCatalogIdAndNameMap(catalogIds);
+    Map<Long, String> schemaIdAndNameMap = getSchemaIdAndNameMap(schemaIds);
+
+    HashMap<Long, String> modelIdAndNameMap = new HashMap<>();
+
+    modelPOs.forEach(
+        modelPO -> {
+          // since the catalog or schema can be deleted, we need to check the 
null value,
+          // and when catalog or schema is deleted, we will set fullName of 
modelPO to
+          // null
+          String catalogName = 
catalogIdAndNameMap.getOrDefault(modelPO.getCatalogId(), null);
+          if (catalogName == null) {
+            LOG.warn("The catalog of model {} may be deleted", 
modelPO.getModelId());
+            modelIdAndNameMap.put(modelPO.getModelId(), null);
+            return;
+          }
+
+          String schemaName = 
schemaIdAndNameMap.getOrDefault(modelPO.getSchemaId(), null);
+          if (schemaName == null) {
+            LOG.warn("The schema of model {} may be deleted", 
modelPO.getModelId());
+            modelIdAndNameMap.put(modelPO.getModelId(), null);
+            return;
+          }
+
+          String fullName = DOT_JOINER.join(catalogName, schemaName, 
modelPO.getModelName());
+          modelIdAndNameMap.put(modelPO.getModelId(), fullName);
+        });
+
+    return modelIdAndNameMap;
+  }
+
+  /**
+   * Retrieves a map of Table object IDs to their full names.
+   *
+   * @param ids A list of Table object IDs to fetch names for.
+   * @return A Map where the key is the Table ID and the value is the Table 
full name. The map may
+   *     contain null values for the names if its parent object is deleted. 
Returns an empty map if
+   *     no Table objects are found for the given IDs. {@code @example} value 
of table full name:
+   *     "catalog1.schema1.table1"
+   */
+  public static Map<Long, String> getTableObjectFullNames(List<Long> ids) {
+    List<TablePO> tablePOs =
+        SessionUtils.getWithoutCommit(
+            TableMetaMapper.class, mapper -> 
mapper.listTablePOsByTableIds(ids));
+
+    if (tablePOs == null || tablePOs.isEmpty()) {
+      return new HashMap<>();
+    }
+
+    List<Long> catalogIds =
+        
tablePOs.stream().map(TablePO::getCatalogId).collect(Collectors.toList());
+    List<Long> schemaIds = 
tablePOs.stream().map(TablePO::getSchemaId).collect(Collectors.toList());
+
+    Map<Long, String> catalogIdAndNameMap = getCatalogIdAndNameMap(catalogIds);
+    Map<Long, String> schemaIdAndNameMap = getSchemaIdAndNameMap(schemaIds);
+
+    HashMap<Long, String> tableIdAndNameMap = new HashMap<>();
+
+    tablePOs.forEach(
+        tablePO -> {
+          // since the catalog or schema can be deleted, we need to check the 
null value,
+          // and when catalog or schema is deleted, we will set fullName of 
tablePO to
+          // null
+          String catalogName = 
catalogIdAndNameMap.getOrDefault(tablePO.getCatalogId(), null);
+          if (catalogName == null) {
+            LOG.warn("The catalog of table {} may be deleted", 
tablePO.getTableId());
+            tableIdAndNameMap.put(tablePO.getTableId(), null);
+            return;
+          }
+
+          String schemaName = 
schemaIdAndNameMap.getOrDefault(tablePO.getSchemaId(), null);
+          if (schemaName == null) {
+            LOG.warn("The schema of table {} may be deleted", 
tablePO.getTableId());
+            tableIdAndNameMap.put(tablePO.getTableId(), null);
+            return;
+          }
+
+          String fullName = DOT_JOINER.join(catalogName, schemaName, 
tablePO.getTableName());
+          tableIdAndNameMap.put(tablePO.getTableId(), fullName);
+        });
+
+    return tableIdAndNameMap;
+  }
+
+  /**
+   * Retrieves a map of Topic object IDs to their full names.
+   *
+   * @param ids A list of Topic object IDs to fetch names for.
+   * @return A Map where the key is the Topic ID and the value is the Topic 
full name. The map may
+   *     contain null values for the names if its parent object is deleted. 
Returns an empty map if
+   *     no Topic objects are found for the given IDs. {@code @example} value 
of topic full name:
+   *     "catalog1.schema1.topic1"
+   */
+  public static Map<Long, String> getTopicObjectFullNames(List<Long> ids) {
+    List<TopicPO> topicPOs =
+        SessionUtils.getWithoutCommit(
+            TopicMetaMapper.class, mapper -> 
mapper.listTopicPOsByTopicIds(ids));
+
+    if (topicPOs == null || topicPOs.isEmpty()) {
+      return new HashMap<>();
+    }
+
+    List<Long> catalogIds =
+        
topicPOs.stream().map(TopicPO::getCatalogId).collect(Collectors.toList());
+    List<Long> schemaIds = 
topicPOs.stream().map(TopicPO::getSchemaId).collect(Collectors.toList());
+
+    Map<Long, String> catalogIdAndNameMap = getCatalogIdAndNameMap(catalogIds);
+    Map<Long, String> schemaIdAndNameMap = getSchemaIdAndNameMap(schemaIds);
+
+    HashMap<Long, String> topicIdAndNameMap = new HashMap<>();
+
+    topicPOs.forEach(
+        topicPO -> {
+          // since the catalog or schema can be deleted, we need to check the 
null value,
+          // and when catalog or schema is deleted, we will set fullName of 
topicPO to
+          // null
+          String catalogName = 
catalogIdAndNameMap.getOrDefault(topicPO.getCatalogId(), null);
+          if (catalogName == null) {
+            LOG.warn("The catalog of topic {} may be deleted", 
topicPO.getTopicId());
+            topicIdAndNameMap.put(topicPO.getTopicId(), null);
+            return;
+          }
+
+          String schemaName = 
schemaIdAndNameMap.getOrDefault(topicPO.getSchemaId(), null);
+          if (schemaName == null) {
+            LOG.warn("The schema of topic {} may be deleted", 
topicPO.getTopicId());
+            topicIdAndNameMap.put(topicPO.getTopicId(), null);
+            return;
+          }
+
+          String fullName = DOT_JOINER.join(catalogName, schemaName, 
topicPO.getTopicName());
+          topicIdAndNameMap.put(topicPO.getTopicId(), fullName);
+        });
+
+    return topicIdAndNameMap;
+  }
+
+  /**
+   * Retrieves a map of Column object IDs to their full names.
+   *
+   * @param ids A list of Column object IDs to fetch names for.
+   * @return A Map where the key is the Column ID and the value is the Column 
full name. The map may
+   *     contain null values for the names if its parent object is deleted. 
Returns an empty map if
+   *     no Column objects are found for the given IDs. {@code @example} value 
of column full name:
+   *     "catalog1.schema1.table1.column1"
+   */
+  public static Map<Long, String> getColumnObjectFullNames(List<Long> ids) {
+    List<ColumnPO> columnPOs =
+        SessionUtils.getWithoutCommit(
+            TableColumnMapper.class, mapper -> 
mapper.listColumnPOsByColumnIds(ids));
+
+    if (columnPOs == null || columnPOs.isEmpty()) {
+      return new HashMap<>();
+    }
+
+    List<Long> catalogIds =
+        
columnPOs.stream().map(ColumnPO::getCatalogId).collect(Collectors.toList());
+    List<Long> schemaIds =
+        
columnPOs.stream().map(ColumnPO::getSchemaId).collect(Collectors.toList());
+    List<Long> tableIds = 
columnPOs.stream().map(ColumnPO::getTableId).collect(Collectors.toList());
+
+    Map<Long, String> catalogIdAndNameMap = getCatalogIdAndNameMap(catalogIds);
+    Map<Long, String> schemaIdAndNameMap = getSchemaIdAndNameMap(schemaIds);
+    Map<Long, String> tableIdAndNameMap = getTableIdAndNameMap(tableIds);
+
+    HashMap<Long, String> columnIdAndNameMap = new HashMap<>();
+
+    columnPOs.forEach(
+        columnPO -> {
+          // since the catalog or schema or table can be deleted, we need to 
check the
+          // null value, and when catalog or schema or table is deleted, we 
will set
+          // fullName of columnPO to null
+          String catalogName = 
catalogIdAndNameMap.getOrDefault(columnPO.getCatalogId(), null);
+          if (catalogName == null) {
+            LOG.warn("The catalog of column {} may be deleted", 
columnPO.getColumnId());
+            columnIdAndNameMap.put(columnPO.getColumnId(), null);
+            return;
+          }
+
+          String schemaName = 
schemaIdAndNameMap.getOrDefault(columnPO.getSchemaId(), null);
+          if (schemaName == null) {
+            LOG.warn("The schema of column {} may be deleted", 
columnPO.getColumnId());
+            columnIdAndNameMap.put(columnPO.getColumnId(), null);
+            return;
+          }
+
+          String tableName = 
tableIdAndNameMap.getOrDefault(columnPO.getTableId(), null);
+          if (tableName == null) {
+            LOG.warn("The table of column {} may be deleted", 
columnPO.getColumnId());
+            columnIdAndNameMap.put(columnPO.getColumnId(), null);
+            return;
+          }
+
+          String fullName =
+              DOT_JOINER.join(catalogName, schemaName, tableName, 
columnPO.getColumnName());
+          columnIdAndNameMap.put(columnPO.getColumnId(), fullName);
+        });
+
+    return columnIdAndNameMap;
+  }
+
+  /**
+   * Retrieves a map of Catalog object IDs to their full names.
+   *
+   * @param ids A list of Catalog object IDs to fetch names for.
+   * @return A Map where the key is the Catalog ID and the value is the 
Catalog full name. The map
+   *     may contain null values for the names if its parent object is 
deleted. Returns an empty map
+   *     if no Catalog objects are found for the given IDs. {@code @example} 
value of catalog full
+   *     name: "catalog1"
+   */
+  public static Map<Long, String> getCatalogObjectFullNames(List<Long> ids) {
+    List<CatalogPO> catalogPOs =
+        SessionUtils.getWithoutCommit(
+            CatalogMetaMapper.class, mapper -> 
mapper.listCatalogPOsByCatalogIds(ids));
+
+    if (catalogPOs == null || catalogPOs.isEmpty()) {
+      return new HashMap<>();
+    }
+
+    HashMap<Long, String> catalogIdAndNameMap = new HashMap<>();
+
+    catalogPOs.forEach(
+        catalogPO ->
+            catalogIdAndNameMap.put(
+                catalogPO.getCatalogId(),
+                catalogPO.getCatalogId() == null ? null : 
catalogPO.getCatalogName()));
+
+    return catalogIdAndNameMap;
+  }
+
+  /**
+   * Retrieves a map of Schema object IDs to their full names.
+   *
+   * @param ids A list of Schema object IDs to fetch names for.
+   * @return A Map where the key is the Schema ID and the value is the Schema 
full name. The map may
+   *     contain null values for the names if its parent object is deleted. 
Returns an empty map if
+   *     no Schema objects are found for the given IDs. {@code @example} value 
of schema full name:
+   *     "catalog1.schema1"
+   */
+  public static Map<Long, String> getSchemaObjectFullNames(List<Long> ids) {
+    List<SchemaPO> schemaPOs =
+        SessionUtils.getWithoutCommit(
+            SchemaMetaMapper.class, mapper -> 
mapper.listSchemaPOsBySchemaIds(ids));
+
+    if (schemaPOs == null || schemaPOs.isEmpty()) {
+      return new HashMap<>();
+    }
+
+    List<Long> catalogIds =
+        
schemaPOs.stream().map(SchemaPO::getCatalogId).collect(Collectors.toList());
+
+    Map<Long, String> catalogIdAndNameMap = getCatalogIdAndNameMap(catalogIds);
+
+    HashMap<Long, String> schemaIdAndNameMap = new HashMap<>();
+
+    schemaPOs.forEach(
+        schemaPO -> {
+          if (schemaPO.getSchemaId() == null) {

Review Comment:
   This is unnecessary, I've removed it.



-- 
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: commits-unsubscr...@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to