This is an automated email from the ASF dual-hosted git repository.
liuxun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new bec35a6f81 [#4305] improvement(core): Improved the way of fill
parentEntityId in POBuilder (#6114)
bec35a6f81 is described below
commit bec35a6f81dd52d321f4d8e8d071580c9198f407
Author: luoshipeng <[email protected]>
AuthorDate: Tue Jan 7 11:34:35 2025 +0800
[#4305] improvement(core): Improved the way of fill parentEntityId in
POBuilder (#6114)
### What changes were proposed in this pull request?
remove the for each statement, and get parentEntityId directly.
### Why are the changes needed?
issue: https://github.com/apache/gravitino/issues/4305
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
ut
---------
Co-authored-by: luoshipeng <[email protected]>
---
.../relational/service/CommonMetaService.java | 25 +++++++++++++++++++++
.../relational/service/FilesetMetaService.java | 26 +++++-----------------
.../relational/service/ModelMetaService.java | 18 ++++-----------
.../relational/service/SchemaMetaService.java | 20 ++++-------------
.../relational/service/TableMetaService.java | 26 +++++-----------------
.../relational/service/TopicMetaService.java | 26 +++++-----------------
6 files changed, 48 insertions(+), 93 deletions(-)
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/service/CommonMetaService.java
b/core/src/main/java/org/apache/gravitino/storage/relational/service/CommonMetaService.java
index f990e94fdc..bdab2ad9fe 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/service/CommonMetaService.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/service/CommonMetaService.java
@@ -57,4 +57,29 @@ public class CommonMetaService {
"Parent entity id should not be null and should be greater than 0.");
return parentEntityId;
}
+
+ public Long[] getParentEntityIdsByNamespace(Namespace namespace) {
+ Preconditions.checkArgument(
+ !namespace.isEmpty() && namespace.levels().length <= 3,
+ "Namespace should not be empty and length should be less than or equal
to 3.");
+ Long[] parentEntityIds = new Long[namespace.levels().length];
+ if (namespace.levels().length >= 1) {
+ parentEntityIds[0] =
+
MetalakeMetaService.getInstance().getMetalakeIdByName(namespace.level(0));
+ }
+
+ if (namespace.levels().length >= 2) {
+ parentEntityIds[1] =
+ CatalogMetaService.getInstance()
+ .getCatalogIdByMetalakeIdAndName(parentEntityIds[0],
namespace.level(1));
+ }
+
+ if (namespace.levels().length >= 3) {
+ parentEntityIds[2] =
+ SchemaMetaService.getInstance()
+ .getSchemaIdByCatalogIdAndName(parentEntityIds[1],
namespace.level(2));
+ }
+
+ return parentEntityIds;
+ }
}
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/service/FilesetMetaService.java
b/core/src/main/java/org/apache/gravitino/storage/relational/service/FilesetMetaService.java
index e049f43640..9233005c34 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/service/FilesetMetaService.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/service/FilesetMetaService.java
@@ -314,26 +314,10 @@ public class FilesetMetaService {
private void fillFilesetPOBuilderParentEntityId(FilesetPO.Builder builder,
Namespace namespace) {
NamespaceUtil.checkFileset(namespace);
- Long parentEntityId = null;
- for (int level = 0; level < namespace.levels().length; level++) {
- String name = namespace.level(level);
- switch (level) {
- case 0:
- parentEntityId =
MetalakeMetaService.getInstance().getMetalakeIdByName(name);
- builder.withMetalakeId(parentEntityId);
- continue;
- case 1:
- parentEntityId =
- CatalogMetaService.getInstance()
- .getCatalogIdByMetalakeIdAndName(parentEntityId, name);
- builder.withCatalogId(parentEntityId);
- continue;
- case 2:
- parentEntityId =
-
SchemaMetaService.getInstance().getSchemaIdByCatalogIdAndName(parentEntityId,
name);
- builder.withSchemaId(parentEntityId);
- break;
- }
- }
+ Long[] parentEntityIds =
+
CommonMetaService.getInstance().getParentEntityIdsByNamespace(namespace);
+ builder.withMetalakeId(parentEntityIds[0]);
+ builder.withCatalogId(parentEntityIds[1]);
+ builder.withSchemaId(parentEntityIds[2]);
}
}
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/service/ModelMetaService.java
b/core/src/main/java/org/apache/gravitino/storage/relational/service/ModelMetaService.java
index 2da43755c5..0197dfdd2d 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/service/ModelMetaService.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/service/ModelMetaService.java
@@ -172,20 +172,10 @@ public class ModelMetaService {
private void fillModelPOBuilderParentEntityId(ModelPO.Builder builder,
Namespace ns) {
NamespaceUtil.checkModel(ns);
- String metalake = ns.level(0);
- String catalog = ns.level(1);
- String schema = ns.level(2);
-
- Long metalakeId =
MetalakeMetaService.getInstance().getMetalakeIdByName(metalake);
- builder.withMetalakeId(metalakeId);
-
- Long catalogId =
-
CatalogMetaService.getInstance().getCatalogIdByMetalakeIdAndName(metalakeId,
catalog);
- builder.withCatalogId(catalogId);
-
- Long schemaId =
-
SchemaMetaService.getInstance().getSchemaIdByCatalogIdAndName(catalogId,
schema);
- builder.withSchemaId(schemaId);
+ Long[] parentEntityIds =
CommonMetaService.getInstance().getParentEntityIdsByNamespace(ns);
+ builder.withMetalakeId(parentEntityIds[0]);
+ builder.withCatalogId(parentEntityIds[1]);
+ builder.withSchemaId(parentEntityIds[2]);
}
ModelPO getModelPOByIdentifier(NameIdentifier ident) {
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java
b/core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java
index 4c9c828cb9..f300e70cae 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java
@@ -316,21 +316,9 @@ public class SchemaMetaService {
private void fillSchemaPOBuilderParentEntityId(SchemaPO.Builder builder,
Namespace namespace) {
NamespaceUtil.checkSchema(namespace);
- Long parentEntityId = null;
- for (int level = 0; level < namespace.levels().length; level++) {
- String name = namespace.level(level);
- switch (level) {
- case 0:
- parentEntityId =
MetalakeMetaService.getInstance().getMetalakeIdByName(name);
- builder.withMetalakeId(parentEntityId);
- continue;
- case 1:
- parentEntityId =
- CatalogMetaService.getInstance()
- .getCatalogIdByMetalakeIdAndName(parentEntityId, name);
- builder.withCatalogId(parentEntityId);
- break;
- }
- }
+ Long[] parentEntityIds =
+
CommonMetaService.getInstance().getParentEntityIdsByNamespace(namespace);
+ builder.withMetalakeId(parentEntityIds[0]);
+ builder.withCatalogId(parentEntityIds[1]);
}
}
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java
b/core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java
index 248dedd8a7..bc44ac43a9 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java
@@ -253,27 +253,11 @@ public class TableMetaService {
private void fillTablePOBuilderParentEntityId(TablePO.Builder builder,
Namespace namespace) {
NamespaceUtil.checkTable(namespace);
- Long parentEntityId = null;
- for (int level = 0; level < namespace.levels().length; level++) {
- String name = namespace.level(level);
- switch (level) {
- case 0:
- parentEntityId =
MetalakeMetaService.getInstance().getMetalakeIdByName(name);
- builder.withMetalakeId(parentEntityId);
- continue;
- case 1:
- parentEntityId =
- CatalogMetaService.getInstance()
- .getCatalogIdByMetalakeIdAndName(parentEntityId, name);
- builder.withCatalogId(parentEntityId);
- continue;
- case 2:
- parentEntityId =
-
SchemaMetaService.getInstance().getSchemaIdByCatalogIdAndName(parentEntityId,
name);
- builder.withSchemaId(parentEntityId);
- break;
- }
- }
+ Long[] parentEntityIds =
+
CommonMetaService.getInstance().getParentEntityIdsByNamespace(namespace);
+ builder.withMetalakeId(parentEntityIds[0]);
+ builder.withCatalogId(parentEntityIds[1]);
+ builder.withSchemaId(parentEntityIds[2]);
}
private TablePO getTablePOBySchemaIdAndName(Long schemaId, String tableName)
{
diff --git
a/core/src/main/java/org/apache/gravitino/storage/relational/service/TopicMetaService.java
b/core/src/main/java/org/apache/gravitino/storage/relational/service/TopicMetaService.java
index 7bc933824a..66a12aa9de 100644
---
a/core/src/main/java/org/apache/gravitino/storage/relational/service/TopicMetaService.java
+++
b/core/src/main/java/org/apache/gravitino/storage/relational/service/TopicMetaService.java
@@ -154,27 +154,11 @@ public class TopicMetaService {
private void fillTopicPOBuilderParentEntityId(TopicPO.Builder builder,
Namespace namespace) {
NamespaceUtil.checkTopic(namespace);
- Long parentEntityId = null;
- for (int level = 0; level < namespace.levels().length; level++) {
- String name = namespace.level(level);
- switch (level) {
- case 0:
- parentEntityId =
MetalakeMetaService.getInstance().getMetalakeIdByName(name);
- builder.withMetalakeId(parentEntityId);
- continue;
- case 1:
- parentEntityId =
- CatalogMetaService.getInstance()
- .getCatalogIdByMetalakeIdAndName(parentEntityId, name);
- builder.withCatalogId(parentEntityId);
- continue;
- case 2:
- parentEntityId =
-
SchemaMetaService.getInstance().getSchemaIdByCatalogIdAndName(parentEntityId,
name);
- builder.withSchemaId(parentEntityId);
- break;
- }
- }
+ Long[] parentEntityIds =
+
CommonMetaService.getInstance().getParentEntityIdsByNamespace(namespace);
+ builder.withMetalakeId(parentEntityIds[0]);
+ builder.withCatalogId(parentEntityIds[1]);
+ builder.withSchemaId(parentEntityIds[2]);
}
public TopicEntity getTopicByIdentifier(NameIdentifier identifier) {