Skip to content

Commit

Permalink
Core: Support removing keys from EnvironmentContext (#12103)
Browse files Browse the repository at this point in the history
  • Loading branch information
rshkv authored Jan 30, 2025
1 parent 2a0d5e8 commit 02c8b2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/org/apache/iceberg/EnvironmentContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@ public static Map<String, String> get() {
public static void put(String key, String value) {
PROPERTIES.put(key, value);
}

/**
* Remove the key from the global properties map.
*
* @param key The key whose value to remove
* @return The previous value associated with the key or null
*/
public static String remove(String key) {
return PROPERTIES.remove(key);
}
}
11 changes: 11 additions & 0 deletions core/src/test/java/org/apache/iceberg/TestEnvironmentContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ public void testDefaultValue() {
assertThat(EnvironmentContext.get().get("iceberg-version"))
.isEqualTo(IcebergBuild.fullVersion());
}

@Test
public void testPutAndRemove() {
EnvironmentContext.put("test-key", "test-value");
assertThat(EnvironmentContext.get()).containsEntry("test-key", "test-value");

assertThat(EnvironmentContext.remove("test-key")).isEqualTo("test-value");
assertThat(EnvironmentContext.get()).doesNotContainKey("test-key");

assertThat(EnvironmentContext.remove("test-key")).isNull();
}
}

0 comments on commit 02c8b2d

Please sign in to comment.