Skip to content

Commit

Permalink
[#4305] improvement(core): Improved the way of fill parentEntityId in…
Browse files Browse the repository at this point in the history
… 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: #4305

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

ut

---------

Co-authored-by: luoshipeng <[email protected]>
  • Loading branch information
luoshipeng and luoshipeng authored Jan 7, 2025
1 parent caf42cf commit bec35a6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,29 @@ public Long getParentEntityIdByNamespace(Namespace namespace) {
"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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,26 +314,10 @@ public int deleteFilesetVersionsByRetentionCount(Long versionRetentionCount, int

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]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,10 @@ ModelPO getModelPOById(Long modelId) {

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,9 @@ public int deleteSchemaMetasByLegacyTimeline(Long legacyTimeline, int limit) {

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]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,27 +253,11 @@ public int deleteTableMetasByLegacyTimeline(Long legacyTimeline, int limit) {

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,11 @@ public TopicPO getTopicPOById(Long topicId) {

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) {
Expand Down

0 comments on commit bec35a6

Please sign in to comment.