This is an automated email from the ASF dual-hosted git repository.
jerryshao pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-1.3 by this push:
new 510627e380 [Cherry-pick to branch-1.3] [#12685] fix(core): Fix
built-in policy supportedObjectTypes validation and error message (#12686)
(#12882)
510627e380 is described below
commit 510627e380deda6d427aa4a08a0ebc8ea981e341
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Sep 3 21:14:15 2026 +0800
[Cherry-pick to branch-1.3] [#12685] fix(core): Fix built-in policy
supportedObjectTypes validation and error message (#12686) (#12882)
**Cherry-pick Information:**
- Original commit: cbadfbf9e98fd700e8ad27d1272ba9ff68e13640
- Target branch: `branch-1.3`
- Status: ✅ Clean cherry-pick (no conflicts)
Co-authored-by: Tanay Paul <[email protected]>
---
.../org/apache/gravitino/policy/PolicyManager.java | 6 ++-
.../apache/gravitino/policy/TestPolicyManager.java | 55 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/apache/gravitino/policy/PolicyManager.java
b/core/src/main/java/org/apache/gravitino/policy/PolicyManager.java
index bcb8bb0439..8f7811074c 100644
--- a/core/src/main/java/org/apache/gravitino/policy/PolicyManager.java
+++ b/core/src/main/java/org/apache/gravitino/policy/PolicyManager.java
@@ -499,11 +499,13 @@ public class PolicyManager implements PolicyDispatcher {
if (policyType != Policy.BuiltInType.CUSTOM) {
// cannot change the supported object types for built-in policies
Preconditions.checkArgument(
- Sets.difference(
+ Sets.symmetricDifference(
policyEntity.content().supportedObjectTypes(),
updateContent.getContent().supportedObjectTypes())
.isEmpty(),
- "Policy content type mismatch: expected %s but got %s");
+ "Policy content type mismatch: expected %s but got %s",
+ policyEntity.content().supportedObjectTypes(),
+ updateContent.getContent().supportedObjectTypes());
}
newContent = updateContent.getContent();
diff --git
a/core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java
b/core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java
index 5b80249042..5f69606220 100644
--- a/core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java
+++ b/core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java
@@ -354,6 +354,61 @@ public class TestPolicyManager {
Assertions.assertTrue(enabledPolicy.enabled());
}
+ @Test
+ public void testAlterBuiltInPolicyContent() {
+ String policyName = "policy_" + UUID.randomUUID().toString().replace("-",
"");
+ policyManager.createPolicy(
+ METALAKE,
+ policyName,
+ Policy.BuiltInType.ICEBERG_COMPACTION,
+ null,
+ true,
+ PolicyContents.icebergDataCompaction());
+
+ // Adding a type not in the original set must be rejected.
+ Set<MetadataObject.Type> withExtra =
+ ImmutableSet.of(
+ MetadataObject.Type.CATALOG,
+ MetadataObject.Type.SCHEMA,
+ MetadataObject.Type.TABLE,
+ MetadataObject.Type.FILESET);
+ PolicyContent addedType = PolicyContents.custom(ImmutableMap.of(),
withExtra, null);
+ IllegalArgumentException addEx =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ policyManager.alterPolicy(
+ METALAKE,
+ policyName,
+ PolicyChange.updateContent("system_iceberg_compaction",
addedType)));
+ Assertions.assertTrue(
+ addEx.getMessage().contains("Policy content type mismatch"),
+ "expected mismatch message, got: " + addEx.getMessage());
+ // Format arguments must be substituted — neither placeholder should
survive literally.
+ Assertions.assertFalse(
+ addEx.getMessage().contains("%s"),
+ "format args were not substituted: " + addEx.getMessage());
+
+ // Removing a type must equally be rejected.
+ Set<MetadataObject.Type> withFewer =
+ ImmutableSet.of(MetadataObject.Type.CATALOG,
MetadataObject.Type.SCHEMA);
+ PolicyContent removedType = PolicyContents.custom(ImmutableMap.of(),
withFewer, null);
+ IllegalArgumentException removeEx =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ policyManager.alterPolicy(
+ METALAKE,
+ policyName,
+ PolicyChange.updateContent("system_iceberg_compaction",
removedType)));
+ Assertions.assertTrue(
+ removeEx.getMessage().contains("Policy content type mismatch"),
+ "expected mismatch message, got: " + removeEx.getMessage());
+ Assertions.assertFalse(
+ removeEx.getMessage().contains("%s"),
+ "format args were not substituted: " + removeEx.getMessage());
+ }
+
@Test
public void testDeletePolicy() {
String policyName = "policy1" + UUID.randomUUID().toString().replace("-",
"");