Skip to content

Commit f51e0b5

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 8d4cacb commit f51e0b5

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ the authentication parameters are picked from the environment or configuration f
4747
- The `DEFAULT_LOCATION_OBJECT_STORAGE_PREFIX_ENABLED` feature was added to support placing tables
4848
at locations that better optimize for object storage.
4949

50+
- Feature configuration `PURGE_VIEWS_ON_DROP` was added to allow dropping views without purging their metadata files.
51+
5052
### Changes
5153

5254
- Polaris Management API clients must be prepared to deal with new attributes in `AwsStorageConfigInfo` objects.

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
@@ -801,7 +801,13 @@ protected ViewOperations newViewOps(TableIdentifier identifier) {
801801

802802
@Override
803803
public boolean dropView(TableIdentifier identifier) {
804-
return dropTableLike(PolarisEntitySubType.ICEBERG_VIEW, identifier, Map.of(), true).isSuccess();
804+
boolean purge =
805+
callContext
806+
.getRealmConfig()
807+
.getConfig(FeatureConfiguration.PURGE_VIEWS_ON_DROP, catalogEntity);
808+
809+
return dropTableLike(PolarisEntitySubType.ICEBERG_VIEW, identifier, Map.of(), purge)
810+
.isSuccess();
805811
}
806812

807813
@Override

0 commit comments

Comments
 (0)