Skip to content

Commit d012870

Browse files
committed
Add feature config to allow dropping views without purging
With tables, the client can decide whether to purge the table on drop or not. However, Polaris Servers used to unconditionally perform the purge on dropping a view. After #1619 that behaviour effectively prevents dropping views if the admin user does not set `DROP_WITH_PURGE_ENABLED`. The latter, though, is not currently advisable per #1617. This change introduces a new feature configuration (`PURGE_VIEWS_ON_DROP`) that allows the admin user to instruct Polaris servers to drop views without purging to achieve operational parity with tables. Fixes #2367
1 parent 596239c commit d012870

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisRestCatalogIntegrationBase.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,32 @@ public void testDropViewStatus() {
11991199
}
12001200
}
12011201

1202+
@Test
1203+
public void testDropViewWithPurge() {
1204+
restCatalog.createNamespace(Namespace.of("ns1"));
1205+
TableIdentifier id = TableIdentifier.of(Namespace.of("ns1"), "view1");
1206+
restCatalog
1207+
.buildView(id)
1208+
.withSchema(SCHEMA)
1209+
.withDefaultNamespace(Namespace.of("ns1"))
1210+
.withQuery("spark", VIEW_QUERY)
1211+
.create();
1212+
1213+
Catalog catalog = managementApi.getCatalog(currentCatalogName);
1214+
Map<String, String> catalogProps = new HashMap<>(catalog.getProperties().toMap());
1215+
catalogProps.put(FeatureConfiguration.DROP_WITH_PURGE_ENABLED.catalogConfig(), "false");
1216+
catalogProps.put(FeatureConfiguration.PURGE_VIEWS_ON_DROP.catalogConfig(), "true");
1217+
managementApi.updateCatalog(catalog, catalogProps);
1218+
1219+
assertThatThrownBy(() -> restCatalog.dropView(id)).isInstanceOf(ForbiddenException.class);
1220+
1221+
catalog = managementApi.getCatalog(currentCatalogName);
1222+
catalogProps.put(FeatureConfiguration.PURGE_VIEWS_ON_DROP.catalogConfig(), "false");
1223+
managementApi.updateCatalog(catalog, catalogProps);
1224+
1225+
assertThatCode(() -> restCatalog.dropView(id)).doesNotThrowAnyException();
1226+
}
1227+
12021228
@Test
12031229
public void testRenameViewStatus() {
12041230
String tableName = "tbl1";

polaris-core/src/main/java/org/apache/polaris/core/config/FeatureConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ public static void enforceFeatureEnabledOrThrow(
191191
.defaultValue(false)
192192
.buildFeatureConfiguration();
193193

194+
public static final FeatureConfiguration<Boolean> PURGE_VIEWS_ON_DROP =
195+
PolarisConfiguration.<Boolean>builder()
196+
.key("PURGE_VIEWS_ON_DROP")
197+
.catalogConfig("polaris.config.purge-views-on-drop")
198+
.description(
199+
"Indicates whether Polaris should purge view metadata files when a view is dropped.")
200+
.defaultValue(true)
201+
.buildFeatureConfiguration();
202+
194203
public static final FeatureConfiguration<Integer> STORAGE_CREDENTIAL_DURATION_SECONDS =
195204
PolarisConfiguration.<Integer>builder()
196205
.key("STORAGE_CREDENTIAL_DURATION_SECONDS")

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,13 @@ protected ViewOperations newViewOps(TableIdentifier identifier) {
807807

808808
@Override
809809
public boolean dropView(TableIdentifier identifier) {
810-
return dropTableLike(PolarisEntitySubType.ICEBERG_VIEW, identifier, Map.of(), true).isSuccess();
810+
boolean purge =
811+
callContext
812+
.getRealmConfig()
813+
.getConfig(FeatureConfiguration.PURGE_VIEWS_ON_DROP, catalogEntity);
814+
815+
return dropTableLike(PolarisEntitySubType.ICEBERG_VIEW, identifier, Map.of(), purge)
816+
.isSuccess();
811817
}
812818

813819
@Override

0 commit comments

Comments
 (0)