Skip to content

Commit 76c5d54

Browse files
authored
Nit: extract getResolvedCatalogEntity method in IcebergCatalogHandler (#2387)
1 parent 850792c commit 76c5d54

File tree

1 file changed

+22
-83
lines changed

1 file changed

+22
-83
lines changed

runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java

Lines changed: 22 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ public IcebergCatalogHandler(
160160
this.catalogHandlerUtils = catalogHandlerUtils;
161161
}
162162

163+
private CatalogEntity getResolvedCatalogEntity() {
164+
PolarisResolvedPathWrapper catalogPath = resolutionManifest.getResolvedReferenceCatalogEntity();
165+
diagnostics.checkNotNull(catalogPath, "No catalog available");
166+
return CatalogEntity.of(catalogPath.getRawLeafEntity());
167+
}
168+
163169
/**
164170
* TODO: Make the helper in org.apache.iceberg.rest.CatalogHandlers public instead of needing to
165171
* copy/paste here.
@@ -200,8 +206,7 @@ public ListNamespacesResponse listNamespaces(
200206

201207
@Override
202208
protected void initializeCatalog() {
203-
CatalogEntity resolvedCatalogEntity =
204-
CatalogEntity.of(resolutionManifest.getResolvedReferenceCatalogEntity().getRawLeafEntity());
209+
CatalogEntity resolvedCatalogEntity = getResolvedCatalogEntity();
205210
ConnectionConfigInfoDpo connectionConfigInfoDpo =
206211
resolvedCatalogEntity.getConnectionConfigInfoDpo();
207212
if (connectionConfigInfoDpo != null) {
@@ -363,12 +368,7 @@ public LoadTableResponse createTableDirect(Namespace namespace, CreateTableReque
363368
TableIdentifier identifier = TableIdentifier.of(namespace, request.name());
364369
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(op, identifier);
365370

366-
CatalogEntity catalog =
367-
CatalogEntity.of(
368-
resolutionManifest
369-
.getResolvedReferenceCatalogEntity()
370-
.getResolvedLeafEntity()
371-
.getEntity());
371+
CatalogEntity catalog = getResolvedCatalogEntity();
372372
if (isStaticFacade(catalog)) {
373373
throw new BadRequestException("Cannot create table on static-facade external catalogs.");
374374
}
@@ -399,12 +399,7 @@ public LoadTableResponse createTableDirectWithWriteDelegation(
399399
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(
400400
op, TableIdentifier.of(namespace, request.name()));
401401

402-
CatalogEntity catalog =
403-
CatalogEntity.of(
404-
resolutionManifest
405-
.getResolvedReferenceCatalogEntity()
406-
.getResolvedLeafEntity()
407-
.getEntity());
402+
CatalogEntity catalog = getResolvedCatalogEntity();
408403
if (isStaticFacade(catalog)) {
409404
throw new BadRequestException("Cannot create table on static-facade external catalogs.");
410405
}
@@ -496,12 +491,7 @@ public LoadTableResponse createTableStaged(Namespace namespace, CreateTableReque
496491
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(
497492
op, TableIdentifier.of(namespace, request.name()));
498493

499-
CatalogEntity catalog =
500-
CatalogEntity.of(
501-
resolutionManifest
502-
.getResolvedReferenceCatalogEntity()
503-
.getResolvedLeafEntity()
504-
.getEntity());
494+
CatalogEntity catalog = getResolvedCatalogEntity();
505495
if (isStaticFacade(catalog)) {
506496
throw new BadRequestException("Cannot create table on static-facade external catalogs.");
507497
}
@@ -516,12 +506,7 @@ public LoadTableResponse createTableStagedWithWriteDelegation(
516506
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(
517507
op, TableIdentifier.of(namespace, request.name()));
518508

519-
CatalogEntity catalog =
520-
CatalogEntity.of(
521-
resolutionManifest
522-
.getResolvedReferenceCatalogEntity()
523-
.getResolvedLeafEntity()
524-
.getEntity());
509+
CatalogEntity catalog = getResolvedCatalogEntity();
525510
if (isStaticFacade(catalog)) {
526511
throw new BadRequestException("Cannot create table on static-facade external catalogs.");
527512
}
@@ -566,12 +551,7 @@ public boolean sendNotification(TableIdentifier identifier, NotificationRequest
566551
authorizeBasicNamespaceOperationOrThrow(
567552
op, Namespace.empty(), extraPassthroughNamespaces, extraPassthroughTableLikes, null);
568553

569-
CatalogEntity catalog =
570-
CatalogEntity.of(
571-
resolutionManifest
572-
.getResolvedReferenceCatalogEntity()
573-
.getResolvedLeafEntity()
574-
.getEntity());
554+
CatalogEntity catalog = getResolvedCatalogEntity();
575555
if (catalog
576556
.getCatalogType()
577557
.equals(org.apache.polaris.core.admin.model.Catalog.TypeEnum.INTERNAL)) {
@@ -682,9 +662,8 @@ public Optional<LoadTableResponse> loadTableWithAccessDelegationIfStale(
682662
read, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
683663
}
684664

685-
PolarisResolvedPathWrapper catalogPath = resolutionManifest.getResolvedReferenceCatalogEntity();
686-
diagnostics.checkNotNull(catalogPath, "No catalog available for loadTable request");
687-
CatalogEntity catalogEntity = CatalogEntity.of(catalogPath.getRawLeafEntity());
665+
CatalogEntity catalogEntity = getResolvedCatalogEntity();
666+
688667
LOGGER.info("Catalog type: {}", catalogEntity.getCatalogType());
689668
LOGGER.info(
690669
"allow external catalog credential vending: {}",
@@ -798,12 +777,7 @@ public LoadTableResponse updateTable(
798777
authorizeBasicTableLikeOperationOrThrow(
799778
op, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
800779

801-
CatalogEntity catalog =
802-
CatalogEntity.of(
803-
resolutionManifest
804-
.getResolvedReferenceCatalogEntity()
805-
.getResolvedLeafEntity()
806-
.getEntity());
780+
CatalogEntity catalog = getResolvedCatalogEntity();
807781
if (isStaticFacade(catalog)) {
808782
throw new BadRequestException("Cannot update table on static-facade external catalogs.");
809783
}
@@ -816,12 +790,7 @@ public LoadTableResponse updateTableForStagedCreate(
816790
PolarisAuthorizableOperation op = PolarisAuthorizableOperation.UPDATE_TABLE_FOR_STAGED_CREATE;
817791
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(op, tableIdentifier);
818792

819-
CatalogEntity catalog =
820-
CatalogEntity.of(
821-
resolutionManifest
822-
.getResolvedReferenceCatalogEntity()
823-
.getResolvedLeafEntity()
824-
.getEntity());
793+
CatalogEntity catalog = getResolvedCatalogEntity();
825794
if (isStaticFacade(catalog)) {
826795
throw new BadRequestException("Cannot update table on static-facade external catalogs.");
827796
}
@@ -842,12 +811,7 @@ public void dropTableWithPurge(TableIdentifier tableIdentifier) {
842811
authorizeBasicTableLikeOperationOrThrow(
843812
op, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
844813

845-
CatalogEntity catalog =
846-
CatalogEntity.of(
847-
resolutionManifest
848-
.getResolvedReferenceCatalogEntity()
849-
.getResolvedLeafEntity()
850-
.getEntity());
814+
CatalogEntity catalog = getResolvedCatalogEntity();
851815
if (isStaticFacade(catalog)) {
852816
throw new BadRequestException("Cannot drop table on static-facade external catalogs.");
853817
}
@@ -868,12 +832,7 @@ public void renameTable(RenameTableRequest request) {
868832
authorizeRenameTableLikeOperationOrThrow(
869833
op, PolarisEntitySubType.ICEBERG_TABLE, request.source(), request.destination());
870834

871-
CatalogEntity catalog =
872-
CatalogEntity.of(
873-
resolutionManifest
874-
.getResolvedReferenceCatalogEntity()
875-
.getResolvedLeafEntity()
876-
.getEntity());
835+
CatalogEntity catalog = getResolvedCatalogEntity();
877836
if (isStaticFacade(catalog)) {
878837
throw new BadRequestException("Cannot rename table on static-facade external catalogs.");
879838
}
@@ -892,12 +851,7 @@ public void commitTransaction(CommitTransactionRequest commitTransactionRequest)
892851
commitTransactionRequest.tableChanges().stream()
893852
.map(UpdateTableRequest::identifier)
894853
.toList());
895-
CatalogEntity catalog =
896-
CatalogEntity.of(
897-
resolutionManifest
898-
.getResolvedReferenceCatalogEntity()
899-
.getResolvedLeafEntity()
900-
.getEntity());
854+
CatalogEntity catalog = getResolvedCatalogEntity();
901855
if (isStaticFacade(catalog)) {
902856
throw new BadRequestException("Cannot update table on static-facade external catalogs.");
903857
}
@@ -1014,12 +968,7 @@ public LoadViewResponse createView(Namespace namespace, CreateViewRequest reques
1014968
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(
1015969
op, TableIdentifier.of(namespace, request.name()));
1016970

1017-
CatalogEntity catalog =
1018-
CatalogEntity.of(
1019-
resolutionManifest
1020-
.getResolvedReferenceCatalogEntity()
1021-
.getResolvedLeafEntity()
1022-
.getEntity());
971+
CatalogEntity catalog = getResolvedCatalogEntity();
1023972
if (isStaticFacade(catalog)) {
1024973
throw new BadRequestException("Cannot create view on static-facade external catalogs.");
1025974
}
@@ -1037,12 +986,7 @@ public LoadViewResponse replaceView(TableIdentifier viewIdentifier, UpdateTableR
1037986
PolarisAuthorizableOperation op = PolarisAuthorizableOperation.REPLACE_VIEW;
1038987
authorizeBasicTableLikeOperationOrThrow(op, PolarisEntitySubType.ICEBERG_VIEW, viewIdentifier);
1039988

1040-
CatalogEntity catalog =
1041-
CatalogEntity.of(
1042-
resolutionManifest
1043-
.getResolvedReferenceCatalogEntity()
1044-
.getResolvedLeafEntity()
1045-
.getEntity());
989+
CatalogEntity catalog = getResolvedCatalogEntity();
1046990
if (isStaticFacade(catalog)) {
1047991
throw new BadRequestException("Cannot replace view on static-facade external catalogs.");
1048992
}
@@ -1069,12 +1013,7 @@ public void renameView(RenameTableRequest request) {
10691013
authorizeRenameTableLikeOperationOrThrow(
10701014
op, PolarisEntitySubType.ICEBERG_VIEW, request.source(), request.destination());
10711015

1072-
CatalogEntity catalog =
1073-
CatalogEntity.of(
1074-
resolutionManifest
1075-
.getResolvedReferenceCatalogEntity()
1076-
.getResolvedLeafEntity()
1077-
.getEntity());
1016+
CatalogEntity catalog = getResolvedCatalogEntity();
10781017
if (isStaticFacade(catalog)) {
10791018
throw new BadRequestException("Cannot rename view on static-facade external catalogs.");
10801019
}

0 commit comments

Comments
 (0)