in polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/Resolver.java [959:1030]
private ResolvedPolarisEntity resolveByName(
@Nonnull List<ResolvedPolarisEntity> toValidate,
long catalogId,
@Nonnull PolarisEntityType entityType,
long parentId,
@Nonnull String entityName) {
// key for that entity
EntityCacheByNameKey nameKey =
new EntityCacheByNameKey(catalogId, parentId, entityType, entityName);
// first check if this entity has not yet been resolved
ResolvedPolarisEntity resolvedEntity = this.resolvedEntriesByName.get(nameKey);
if (resolvedEntity != null) {
return resolvedEntity;
}
// then check if it does not exist in the toValidate list. The same entity might be resolved
// several times with multi-path resolution
for (ResolvedPolarisEntity ce : toValidate) {
PolarisBaseEntity entity = ce.getEntity();
if (entity.getCatalogId() == catalogId
&& entity.getParentId() == parentId
&& entity.getType() == entityType
&& entity.getName().equals(entityName)) {
return ce;
}
}
// get or load by name
if (this.cache != null) {
EntityCacheLookupResult lookupResult =
this.cache.getOrLoadEntityByName(
this.polarisCallContext,
new EntityCacheByNameKey(catalogId, parentId, entityType, entityName));
// if not found
if (lookupResult == null) {
// not found
return null;
} else if (lookupResult.isCacheHit()) {
// found in the cache, we will have to validate this entity
toValidate.add(lookupResult.getCacheEntry());
} else {
// entry cannot be null
this.diagnostics.checkNotNull(lookupResult.getCacheEntry(), "cache_entry_is_null");
// if not found in cache, it was loaded from backend, hence it has been resolved
this.addToResolved(lookupResult.getCacheEntry());
}
// return the cache entry
return lookupResult.getCacheEntry();
} else {
// If no cache, load directly from metastore manager.
ResolvedEntityResult result =
this.polarisMetaStoreManager.loadResolvedEntityByName(
this.polarisCallContext, catalogId, parentId, entityType, entityName);
if (!result.isSuccess()) {
// not found
return null;
}
resolvedEntity =
new ResolvedPolarisEntity(
this.polarisCallContext.getDiagServices(),
result.getEntity(),
result.getEntityGrantRecords(),
result.getGrantRecordsVersion());
this.addToResolved(resolvedEntity);
return resolvedEntity;
}
}