From aa6670ce85028ba4a6aa5991c75c99fb8761924b Mon Sep 17 00:00:00 2001 From: Alexandre Dutra Date: Tue, 19 Aug 2025 12:11:28 +0200 Subject: [PATCH] Nit: extract getResolvedCatalogEntity method in IcebergCatalogHandler --- .../iceberg/IcebergCatalogHandler.java | 105 ++++-------------- 1 file changed, 22 insertions(+), 83 deletions(-) diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java index 33b4bef067..e0a9caff9d 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java @@ -160,6 +160,12 @@ public IcebergCatalogHandler( this.catalogHandlerUtils = catalogHandlerUtils; } + private CatalogEntity getResolvedCatalogEntity() { + PolarisResolvedPathWrapper catalogPath = resolutionManifest.getResolvedReferenceCatalogEntity(); + diagnostics.checkNotNull(catalogPath, "No catalog available"); + return CatalogEntity.of(catalogPath.getRawLeafEntity()); + } + /** * TODO: Make the helper in org.apache.iceberg.rest.CatalogHandlers public instead of needing to * copy/paste here. @@ -200,8 +206,7 @@ public ListNamespacesResponse listNamespaces( @Override protected void initializeCatalog() { - CatalogEntity resolvedCatalogEntity = - CatalogEntity.of(resolutionManifest.getResolvedReferenceCatalogEntity().getRawLeafEntity()); + CatalogEntity resolvedCatalogEntity = getResolvedCatalogEntity(); ConnectionConfigInfoDpo connectionConfigInfoDpo = resolvedCatalogEntity.getConnectionConfigInfoDpo(); if (connectionConfigInfoDpo != null) { @@ -363,12 +368,7 @@ public LoadTableResponse createTableDirect(Namespace namespace, CreateTableReque TableIdentifier identifier = TableIdentifier.of(namespace, request.name()); authorizeCreateTableLikeUnderNamespaceOperationOrThrow(op, identifier); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot create table on static-facade external catalogs."); } @@ -399,12 +399,7 @@ public LoadTableResponse createTableDirectWithWriteDelegation( authorizeCreateTableLikeUnderNamespaceOperationOrThrow( op, TableIdentifier.of(namespace, request.name())); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot create table on static-facade external catalogs."); } @@ -496,12 +491,7 @@ public LoadTableResponse createTableStaged(Namespace namespace, CreateTableReque authorizeCreateTableLikeUnderNamespaceOperationOrThrow( op, TableIdentifier.of(namespace, request.name())); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot create table on static-facade external catalogs."); } @@ -516,12 +506,7 @@ public LoadTableResponse createTableStagedWithWriteDelegation( authorizeCreateTableLikeUnderNamespaceOperationOrThrow( op, TableIdentifier.of(namespace, request.name())); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot create table on static-facade external catalogs."); } @@ -566,12 +551,7 @@ public boolean sendNotification(TableIdentifier identifier, NotificationRequest authorizeBasicNamespaceOperationOrThrow( op, Namespace.empty(), extraPassthroughNamespaces, extraPassthroughTableLikes, null); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (catalog .getCatalogType() .equals(org.apache.polaris.core.admin.model.Catalog.TypeEnum.INTERNAL)) { @@ -682,9 +662,8 @@ public Optional loadTableWithAccessDelegationIfStale( read, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier); } - PolarisResolvedPathWrapper catalogPath = resolutionManifest.getResolvedReferenceCatalogEntity(); - diagnostics.checkNotNull(catalogPath, "No catalog available for loadTable request"); - CatalogEntity catalogEntity = CatalogEntity.of(catalogPath.getRawLeafEntity()); + CatalogEntity catalogEntity = getResolvedCatalogEntity(); + LOGGER.info("Catalog type: {}", catalogEntity.getCatalogType()); LOGGER.info( "allow external catalog credential vending: {}", @@ -798,12 +777,7 @@ public LoadTableResponse updateTable( authorizeBasicTableLikeOperationOrThrow( op, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot update table on static-facade external catalogs."); } @@ -816,12 +790,7 @@ public LoadTableResponse updateTableForStagedCreate( PolarisAuthorizableOperation op = PolarisAuthorizableOperation.UPDATE_TABLE_FOR_STAGED_CREATE; authorizeCreateTableLikeUnderNamespaceOperationOrThrow(op, tableIdentifier); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot update table on static-facade external catalogs."); } @@ -842,12 +811,7 @@ public void dropTableWithPurge(TableIdentifier tableIdentifier) { authorizeBasicTableLikeOperationOrThrow( op, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot drop table on static-facade external catalogs."); } @@ -868,12 +832,7 @@ public void renameTable(RenameTableRequest request) { authorizeRenameTableLikeOperationOrThrow( op, PolarisEntitySubType.ICEBERG_TABLE, request.source(), request.destination()); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot rename table on static-facade external catalogs."); } @@ -892,12 +851,7 @@ public void commitTransaction(CommitTransactionRequest commitTransactionRequest) commitTransactionRequest.tableChanges().stream() .map(UpdateTableRequest::identifier) .toList()); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot update table on static-facade external catalogs."); } @@ -1014,12 +968,7 @@ public LoadViewResponse createView(Namespace namespace, CreateViewRequest reques authorizeCreateTableLikeUnderNamespaceOperationOrThrow( op, TableIdentifier.of(namespace, request.name())); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot create view on static-facade external catalogs."); } @@ -1037,12 +986,7 @@ public LoadViewResponse replaceView(TableIdentifier viewIdentifier, UpdateTableR PolarisAuthorizableOperation op = PolarisAuthorizableOperation.REPLACE_VIEW; authorizeBasicTableLikeOperationOrThrow(op, PolarisEntitySubType.ICEBERG_VIEW, viewIdentifier); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot replace view on static-facade external catalogs."); } @@ -1069,12 +1013,7 @@ public void renameView(RenameTableRequest request) { authorizeRenameTableLikeOperationOrThrow( op, PolarisEntitySubType.ICEBERG_VIEW, request.source(), request.destination()); - CatalogEntity catalog = - CatalogEntity.of( - resolutionManifest - .getResolvedReferenceCatalogEntity() - .getResolvedLeafEntity() - .getEntity()); + CatalogEntity catalog = getResolvedCatalogEntity(); if (isStaticFacade(catalog)) { throw new BadRequestException("Cannot rename view on static-facade external catalogs."); }