jerqi commented on code in PR #9091: URL: https://github.com/apache/gravitino/pull/9091#discussion_r2558696597
########## core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStoreIdResolver.java: ########## @@ -0,0 +1,206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational; + +import com.google.common.collect.ImmutableSet; +import java.util.Set; +import org.apache.gravitino.Entity; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.meta.EntityIdResolver; +import org.apache.gravitino.meta.NamespacedEntityId; +import org.apache.gravitino.storage.relational.helper.CatalogIds; +import org.apache.gravitino.storage.relational.helper.SchemaIds; +import org.apache.gravitino.storage.relational.service.CatalogMetaService; +import org.apache.gravitino.storage.relational.service.FilesetMetaService; +import org.apache.gravitino.storage.relational.service.GroupMetaService; +import org.apache.gravitino.storage.relational.service.MetalakeMetaService; +import org.apache.gravitino.storage.relational.service.ModelMetaService; +import org.apache.gravitino.storage.relational.service.RoleMetaService; +import org.apache.gravitino.storage.relational.service.SchemaMetaService; +import org.apache.gravitino.storage.relational.service.TableColumnMetaService; +import org.apache.gravitino.storage.relational.service.TableMetaService; +import org.apache.gravitino.storage.relational.service.TagMetaService; +import org.apache.gravitino.storage.relational.service.TopicMetaService; +import org.apache.gravitino.storage.relational.service.UserMetaService; +import org.apache.gravitino.utils.NameIdentifierUtil; + +public class RelationalEntityStoreIdResolver implements EntityIdResolver { + private static final Set<Entity.EntityType> ENTITY_TYPES_REQUIRING_METALAKE_ID = + ImmutableSet.of( + Entity.EntityType.METALAKE, + Entity.EntityType.ROLE, + Entity.EntityType.USER, + Entity.EntityType.GROUP, + Entity.EntityType.TAG); + private static final Set<Entity.EntityType> ENTITY_TYPES_REQURING_CATALOG_IDS = + ImmutableSet.of(Entity.EntityType.CATALOG); + private static final Set<Entity.EntityType> ENTITY_TYPES_REQURING_SCHEMA_IDS = + ImmutableSet.of( + Entity.EntityType.SCHEMA, + Entity.EntityType.TABLE, + Entity.EntityType.FILESET, + Entity.EntityType.TOPIC, + Entity.EntityType.MODEL, + Entity.EntityType.COLUMN); + + @Override + public NamespacedEntityId getEntityIds(NameIdentifier nameIdentifier, Entity.EntityType type) { + if (ENTITY_TYPES_REQUIRING_METALAKE_ID.contains(type)) { + return getEntityIdsAboutMetalake(nameIdentifier, type); + + } else if (ENTITY_TYPES_REQURING_CATALOG_IDS.contains(type)) { + CatalogIds catalogIds = + CatalogMetaService.getInstance() + .getCatalogIdByMetalakeAndCatalogName( + NameIdentifierUtil.getMetalake(nameIdentifier), + NameIdentifierUtil.getCatalogIdentifier(nameIdentifier).name()); + return new NamespacedEntityId(catalogIds.getCatalogId(), catalogIds.getMetalakeId()); + + } else if (ENTITY_TYPES_REQURING_SCHEMA_IDS.contains(type)) { + return getEntityIdsAboutSchema(nameIdentifier, type); + + } else { + throw new IllegalArgumentException("Unsupported entity type: " + type); + } + } + + @Override + public Long getEntityId(NameIdentifier nameIdentifier, Entity.EntityType type) { + if (ENTITY_TYPES_REQUIRING_METALAKE_ID.contains(type)) { + return getEntityIdsAboutMetalake(nameIdentifier, type).entityId(); + + } else if (ENTITY_TYPES_REQURING_CATALOG_IDS.contains(type)) { + return CatalogMetaService.getInstance() + .getCatalogIdByMetalakeAndCatalogName( + NameIdentifierUtil.getMetalake(nameIdentifier), + NameIdentifierUtil.getCatalogIdentifier(nameIdentifier).name()) + .getCatalogId(); + + } else if (ENTITY_TYPES_REQURING_SCHEMA_IDS.contains(type)) { + return getEntityIdsAboutSchema(nameIdentifier, type).entityId(); + + } else { + throw new IllegalArgumentException("Unsupported entity type: " + type); + } + } + + private NamespacedEntityId getEntityIdsAboutMetalake( Review Comment: Fixed. -- 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]
