Skip to content

Commit 1fe6205

Browse files
authored
Nit: add methods isExternal and isStaticFacade to CatalogEntity (#2386)
1 parent 42245cb commit 1fe6205

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,19 @@ public Catalog.TypeEnum getCatalogType() {
205205
.orElse(null);
206206
}
207207

208+
public boolean isExternal() {
209+
return getCatalogType() == Catalog.TypeEnum.EXTERNAL;
210+
}
211+
208212
public boolean isPassthroughFacade() {
209213
return getInternalPropertiesAsMap()
210214
.containsKey(PolarisEntityConstants.getConnectionConfigInfoPropertyName());
211215
}
212216

217+
public boolean isStaticFacade() {
218+
return isExternal() && !isPassthroughFacade();
219+
}
220+
213221
public ConnectionConfigInfoDpo getConnectionConfigInfoDpo() {
214222
String configStr =
215223
getInternalPropertiesAsMap()

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,6 @@ public CreateNamespaceResponse createNamespace(CreateNamespaceRequest request) {
290290
}
291291
}
292292

293-
private static boolean isStaticFacade(CatalogEntity catalog) {
294-
return org.apache.polaris.core.admin.model.Catalog.TypeEnum.EXTERNAL.equals(
295-
catalog.getCatalogType())
296-
&& !catalog.isPassthroughFacade();
297-
}
298-
299293
public GetNamespaceResponse loadNamespaceMetadata(Namespace namespace) {
300294
PolarisAuthorizableOperation op = PolarisAuthorizableOperation.LOAD_NAMESPACE_METADATA;
301295
authorizeBasicNamespaceOperationOrThrow(op, namespace);
@@ -369,7 +363,7 @@ public LoadTableResponse createTableDirect(Namespace namespace, CreateTableReque
369363
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(op, identifier);
370364

371365
CatalogEntity catalog = getResolvedCatalogEntity();
372-
if (isStaticFacade(catalog)) {
366+
if (catalog.isStaticFacade()) {
373367
throw new BadRequestException("Cannot create table on static-facade external catalogs.");
374368
}
375369
CreateTableRequest requestWithoutReservedProperties =
@@ -400,7 +394,7 @@ public LoadTableResponse createTableDirectWithWriteDelegation(
400394
op, TableIdentifier.of(namespace, request.name()));
401395

402396
CatalogEntity catalog = getResolvedCatalogEntity();
403-
if (isStaticFacade(catalog)) {
397+
if (catalog.isStaticFacade()) {
404398
throw new BadRequestException("Cannot create table on static-facade external catalogs.");
405399
}
406400
request.validate();
@@ -492,7 +486,7 @@ public LoadTableResponse createTableStaged(Namespace namespace, CreateTableReque
492486
op, TableIdentifier.of(namespace, request.name()));
493487

494488
CatalogEntity catalog = getResolvedCatalogEntity();
495-
if (isStaticFacade(catalog)) {
489+
if (catalog.isStaticFacade()) {
496490
throw new BadRequestException("Cannot create table on static-facade external catalogs.");
497491
}
498492
TableMetadata metadata = stageTableCreateHelper(namespace, request);
@@ -507,7 +501,7 @@ public LoadTableResponse createTableStagedWithWriteDelegation(
507501
op, TableIdentifier.of(namespace, request.name()));
508502

509503
CatalogEntity catalog = getResolvedCatalogEntity();
510-
if (isStaticFacade(catalog)) {
504+
if (catalog.isStaticFacade()) {
511505
throw new BadRequestException("Cannot create table on static-facade external catalogs.");
512506
}
513507
TableIdentifier ident = TableIdentifier.of(namespace, request.name());
@@ -778,7 +772,7 @@ public LoadTableResponse updateTable(
778772
op, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
779773

780774
CatalogEntity catalog = getResolvedCatalogEntity();
781-
if (isStaticFacade(catalog)) {
775+
if (catalog.isStaticFacade()) {
782776
throw new BadRequestException("Cannot update table on static-facade external catalogs.");
783777
}
784778
return catalogHandlerUtils.updateTable(
@@ -791,7 +785,7 @@ public LoadTableResponse updateTableForStagedCreate(
791785
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(op, tableIdentifier);
792786

793787
CatalogEntity catalog = getResolvedCatalogEntity();
794-
if (isStaticFacade(catalog)) {
788+
if (catalog.isStaticFacade()) {
795789
throw new BadRequestException("Cannot update table on static-facade external catalogs.");
796790
}
797791
return catalogHandlerUtils.updateTable(
@@ -812,7 +806,7 @@ public void dropTableWithPurge(TableIdentifier tableIdentifier) {
812806
op, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
813807

814808
CatalogEntity catalog = getResolvedCatalogEntity();
815-
if (isStaticFacade(catalog)) {
809+
if (catalog.isStaticFacade()) {
816810
throw new BadRequestException("Cannot drop table on static-facade external catalogs.");
817811
}
818812
catalogHandlerUtils.purgeTable(baseCatalog, tableIdentifier);
@@ -833,7 +827,7 @@ public void renameTable(RenameTableRequest request) {
833827
op, PolarisEntitySubType.ICEBERG_TABLE, request.source(), request.destination());
834828

835829
CatalogEntity catalog = getResolvedCatalogEntity();
836-
if (isStaticFacade(catalog)) {
830+
if (catalog.isStaticFacade()) {
837831
throw new BadRequestException("Cannot rename table on static-facade external catalogs.");
838832
}
839833
catalogHandlerUtils.renameTable(baseCatalog, request);
@@ -852,7 +846,7 @@ public void commitTransaction(CommitTransactionRequest commitTransactionRequest)
852846
.map(UpdateTableRequest::identifier)
853847
.toList());
854848
CatalogEntity catalog = getResolvedCatalogEntity();
855-
if (isStaticFacade(catalog)) {
849+
if (catalog.isStaticFacade()) {
856850
throw new BadRequestException("Cannot update table on static-facade external catalogs.");
857851
}
858852

@@ -969,7 +963,7 @@ public LoadViewResponse createView(Namespace namespace, CreateViewRequest reques
969963
op, TableIdentifier.of(namespace, request.name()));
970964

971965
CatalogEntity catalog = getResolvedCatalogEntity();
972-
if (isStaticFacade(catalog)) {
966+
if (catalog.isStaticFacade()) {
973967
throw new BadRequestException("Cannot create view on static-facade external catalogs.");
974968
}
975969
return catalogHandlerUtils.createView(viewCatalog, namespace, request);
@@ -987,7 +981,7 @@ public LoadViewResponse replaceView(TableIdentifier viewIdentifier, UpdateTableR
987981
authorizeBasicTableLikeOperationOrThrow(op, PolarisEntitySubType.ICEBERG_VIEW, viewIdentifier);
988982

989983
CatalogEntity catalog = getResolvedCatalogEntity();
990-
if (isStaticFacade(catalog)) {
984+
if (catalog.isStaticFacade()) {
991985
throw new BadRequestException("Cannot replace view on static-facade external catalogs.");
992986
}
993987
return catalogHandlerUtils.updateView(viewCatalog, viewIdentifier, applyUpdateFilters(request));
@@ -1014,7 +1008,7 @@ public void renameView(RenameTableRequest request) {
10141008
op, PolarisEntitySubType.ICEBERG_VIEW, request.source(), request.destination());
10151009

10161010
CatalogEntity catalog = getResolvedCatalogEntity();
1017-
if (isStaticFacade(catalog)) {
1011+
if (catalog.isStaticFacade()) {
10181012
throw new BadRequestException("Cannot rename view on static-facade external catalogs.");
10191013
}
10201014
catalogHandlerUtils.renameView(viewCatalog, request);

0 commit comments

Comments
 (0)