Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package org.apache.polaris.core.persistence.resolver;

import jakarta.annotation.Nullable;
import java.util.Optional;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
Expand All @@ -29,6 +32,13 @@
public interface PolarisResolutionManifestCatalogView {
PolarisResolvedPathWrapper getResolvedReferenceCatalogEntity();

default @Nullable CatalogEntity getResolvedCatalogEntity() {
return Optional.ofNullable(getResolvedReferenceCatalogEntity())
.map(PolarisResolvedPathWrapper::getRawLeafEntity)
.map(CatalogEntity::of)
.orElse(null);
}

PolarisResolvedPathWrapper getResolvedPath(Object key);

PolarisResolvedPathWrapper getResolvedPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ private PolarisResolutionManifest newResolutionManifest(@Nullable String catalog
}

private Optional<CatalogEntity> currentCatalog() {
return Optional.ofNullable(resolutionManifest.getResolvedReferenceCatalogEntity())
.map(path -> CatalogEntity.of(path.getRawLeafEntity()));
return Optional.ofNullable(resolutionManifest.getResolvedCatalogEntity());
}

private Optional<PrincipalEntity> findPrincipalByName(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public GenericTableCatalogHandler(

@Override
protected void initializeCatalog() {
CatalogEntity resolvedCatalogEntity =
CatalogEntity.of(resolutionManifest.getResolvedReferenceCatalogEntity().getRawLeafEntity());
CatalogEntity resolvedCatalogEntity = resolutionManifest.getResolvedCatalogEntity();
ConnectionConfigInfoDpo connectionConfigInfoDpo =
resolvedCatalogEntity.getConnectionConfigInfoDpo();
if (connectionConfigInfoDpo != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public PolarisGenericTableCatalog(
PolarisResolutionManifestCatalogView resolvedEntityView) {
this.callContext = callContext;
this.resolvedEntityView = resolvedEntityView;
this.catalogEntity =
CatalogEntity.of(resolvedEntityView.getResolvedReferenceCatalogEntity().getRawLeafEntity());
this.catalogEntity = resolvedEntityView.getResolvedCatalogEntity();
this.catalogId = catalogEntity.getId();
this.metaStoreManager = metaStoreManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ public IcebergCatalog(
this.callContext = callContext;
this.realmConfig = callContext.getRealmConfig();
this.resolvedEntityView = resolvedEntityView;
this.catalogEntity =
CatalogEntity.of(resolvedEntityView.getResolvedReferenceCatalogEntity().getRawLeafEntity());
this.catalogEntity = resolvedEntityView.getResolvedCatalogEntity();
this.securityContext = securityContext;
this.taskExecutor = taskExecutor;
this.catalogId = catalogEntity.getId();
Expand Down Expand Up @@ -534,7 +533,7 @@ private String resolveNamespaceLocation(Namespace namespace, Map<String, String>
List<PolarisEntity> parentPath =
namespace.length() > 1
? getResolvedParentNamespace(namespace).getRawFullPath()
: List.of(resolvedEntityView.getResolvedReferenceCatalogEntity().getRawLeafEntity());
: List.of(resolvedEntityView.getResolvedCatalogEntity());

String parentLocation = resolveLocationForPath(diagnostics, parentPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ public IcebergCatalogHandler(
}

private CatalogEntity getResolvedCatalogEntity() {
PolarisResolvedPathWrapper catalogPath = resolutionManifest.getResolvedReferenceCatalogEntity();
diagnostics.checkNotNull(catalogPath, "No catalog available");
return CatalogEntity.of(catalogPath.getRawLeafEntity());
CatalogEntity catalogEntity = resolutionManifest.getResolvedCatalogEntity();
diagnostics.checkNotNull(catalogEntity, "No catalog available");
return catalogEntity;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public PolicyCatalog(
PolarisResolutionManifestCatalogView resolvedEntityView) {
this.callContext = callContext;
this.resolvedEntityView = resolvedEntityView;
this.catalogEntity =
CatalogEntity.of(resolvedEntityView.getResolvedReferenceCatalogEntity().getRawLeafEntity());
this.catalogEntity = resolvedEntityView.getResolvedCatalogEntity();
this.catalogId = catalogEntity.getId();
this.metaStoreManager = metaStoreManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.polaris.core.auth.PolarisPrincipal;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
import org.apache.polaris.core.persistence.resolver.ResolverFactory;
Expand Down Expand Up @@ -78,9 +77,8 @@ public Catalog createCallContextCatalog(
PolarisPrincipal polarisPrincipal,
SecurityContext securityContext,
final PolarisResolutionManifest resolvedManifest) {
PolarisBaseEntity baseCatalogEntity =
resolvedManifest.getResolvedReferenceCatalogEntity().getRawLeafEntity();
String catalogName = baseCatalogEntity.getName();
CatalogEntity catalog = resolvedManifest.getResolvedCatalogEntity();
String catalogName = catalog.getName();

String realm = context.getRealmContext().getRealmIdentifier();
String catalogKey = realm + "/" + catalogName;
Expand All @@ -99,7 +97,6 @@ public Catalog createCallContextCatalog(
fileIOFactory,
polarisEventListener);

CatalogEntity catalog = CatalogEntity.of(baseCatalogEntity);
Map<String, String> catalogProperties = new HashMap<>(catalog.getPropertiesAsMap());
String defaultBaseLocation = catalog.getBaseLocation();
LOGGER.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.polaris.core.config.FeatureConfiguration;
import org.apache.polaris.core.config.RealmConfig;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.NamespaceEntity;
import org.apache.polaris.core.entity.PolarisEntity;
import org.apache.polaris.core.entity.PolarisEntitySubType;
Expand Down Expand Up @@ -149,9 +150,7 @@ void testGrantPrivilegeOnNamespaceToRole_ThrowsNamespaceNotFoundException() {
when(resolutionManifest.resolveAll()).thenReturn(createSuccessfulResolverStatus());

PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG);
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
when(catalogWrapper.getRawLeafEntity()).thenReturn(catalogEntity);
when(resolutionManifest.getResolvedReferenceCatalogEntity()).thenReturn(catalogWrapper);
when(resolutionManifest.getResolvedCatalogEntity()).thenReturn(CatalogEntity.of(catalogEntity));

PolarisResolvedPathWrapper catalogRoleWrapper = mock(PolarisResolvedPathWrapper.class);
PolarisEntity catalogRoleEntity =
Expand Down Expand Up @@ -182,9 +181,7 @@ void testGrantPrivilegeOnNamespaceToRole_IncompleteNamespaceThrowsNamespaceNotFo
when(resolutionManifest.resolveAll()).thenReturn(createSuccessfulResolverStatus());

PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG, 1L);
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
when(catalogWrapper.getRawLeafEntity()).thenReturn(catalogEntity);
when(resolutionManifest.getResolvedReferenceCatalogEntity()).thenReturn(catalogWrapper);
when(resolutionManifest.getResolvedCatalogEntity()).thenReturn(CatalogEntity.of(catalogEntity));

PolarisResolvedPathWrapper catalogRoleWrapper = mock(PolarisResolvedPathWrapper.class);
PolarisEntity catalogRoleEntity =
Expand Down Expand Up @@ -297,10 +294,7 @@ void testGrantPrivilegeOnNamespaceToRole_PassthroughFacade() throws Exception {
PolarisPrivilege privilege = PolarisPrivilege.NAMESPACE_FULL_METADATA;

PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG);
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
when(catalogWrapper.getRawLeafEntity()).thenReturn(catalogEntity);
when(resolutionManifest.getResolvedReferenceCatalogEntity()).thenReturn(catalogWrapper);
when(resolutionManifest.getIsPassthroughFacade()).thenReturn(true);
when(resolutionManifest.getResolvedCatalogEntity()).thenReturn(CatalogEntity.of(catalogEntity));

PolarisResolvedPathWrapper catalogRoleWrapper = mock(PolarisResolvedPathWrapper.class);
PolarisEntity catalogRoleEntity =
Expand Down Expand Up @@ -367,10 +361,7 @@ void testGrantPrivilegeOnNamespaceToRole_PassthroughFacade_FeatureDisabled() thr
.thenReturn(false);

PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG);
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
when(catalogWrapper.getRawLeafEntity()).thenReturn(catalogEntity);
when(resolutionManifest.getResolvedReferenceCatalogEntity()).thenReturn(catalogWrapper);
when(resolutionManifest.getIsPassthroughFacade()).thenReturn(true);
when(resolutionManifest.getResolvedCatalogEntity()).thenReturn(CatalogEntity.of(catalogEntity));

PolarisResolvedPathWrapper catalogRoleWrapper = mock(PolarisResolvedPathWrapper.class);
PolarisEntity catalogRoleEntity =
Expand Down Expand Up @@ -404,6 +395,7 @@ void testGrantPrivilegeOnNamespaceToRole_SyntheticEntityCreationFails() throws E
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
when(catalogWrapper.getRawLeafEntity()).thenReturn(catalogEntity);
when(resolutionManifest.getResolvedReferenceCatalogEntity()).thenReturn(catalogWrapper);
when(resolutionManifest.getResolvedCatalogEntity()).thenCallRealMethod();
when(resolutionManifest.getIsPassthroughFacade()).thenReturn(true);

PolarisResolvedPathWrapper catalogRoleWrapper = mock(PolarisResolvedPathWrapper.class);
Expand Down Expand Up @@ -451,9 +443,7 @@ void testGrantPrivilegeOnTableLikeToRole_PassthroughFacade() throws Exception {
PolarisPrivilege privilege = PolarisPrivilege.TABLE_WRITE_DATA;

PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG);
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
when(catalogWrapper.getRawLeafEntity()).thenReturn(catalogEntity);
when(resolutionManifest.getResolvedReferenceCatalogEntity()).thenReturn(catalogWrapper);
when(resolutionManifest.getResolvedCatalogEntity()).thenReturn(CatalogEntity.of(catalogEntity));
when(resolutionManifest.getIsPassthroughFacade()).thenReturn(true);

PolarisResolvedPathWrapper catalogRoleWrapper = mock(PolarisResolvedPathWrapper.class);
Expand Down Expand Up @@ -534,9 +524,7 @@ void testGrantPrivilegeOnTableLikeToRole_PassthroughFacade_FeatureDisabled() thr
.thenReturn(false);

PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG);
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
when(catalogWrapper.getRawLeafEntity()).thenReturn(catalogEntity);
when(resolutionManifest.getResolvedReferenceCatalogEntity()).thenReturn(catalogWrapper);
when(resolutionManifest.getResolvedCatalogEntity()).thenReturn(CatalogEntity.of(catalogEntity));
when(resolutionManifest.getIsPassthroughFacade()).thenReturn(true);

PolarisResolvedPathWrapper catalogRoleWrapper = mock(PolarisResolvedPathWrapper.class);
Expand Down Expand Up @@ -581,9 +569,7 @@ void testGrantPrivilegeOnTableLikeToRole_SyntheticEntityCreationFails() throws E
PolarisPrivilege privilege = PolarisPrivilege.TABLE_WRITE_DATA;

PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG);
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
when(catalogWrapper.getRawLeafEntity()).thenReturn(catalogEntity);
when(resolutionManifest.getResolvedReferenceCatalogEntity()).thenReturn(catalogWrapper);
when(resolutionManifest.getResolvedCatalogEntity()).thenReturn(CatalogEntity.of(catalogEntity));
when(resolutionManifest.getIsPassthroughFacade()).thenReturn(true);

PolarisResolvedPathWrapper catalogRoleWrapper = mock(PolarisResolvedPathWrapper.class);
Expand Down Expand Up @@ -695,9 +681,7 @@ private void setupSuccessfulNamespaceResolution(
when(resolutionManifest.getResolvedPath(eq(namespace))).thenReturn(resolvedPathWrapper);

PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG);
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
when(catalogWrapper.getRawLeafEntity()).thenReturn(catalogEntity);
when(resolutionManifest.getResolvedReferenceCatalogEntity()).thenReturn(catalogWrapper);
when(resolutionManifest.getResolvedCatalogEntity()).thenReturn(CatalogEntity.of(catalogEntity));

PolarisResolvedPathWrapper catalogRoleWrapper = mock(PolarisResolvedPathWrapper.class);
PolarisEntity catalogRoleEntity =
Expand Down