You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by si...@apache.org on 2022/02/28 15:46:19 UTC
[hudi] branch master updated: [HUDI-3528] Fix String convert issue and overwrite putAll method in TypedProperties.java (#4920)
This is an automated email from the ASF dual-hosted git repository.
sivabalan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 8f1e4f5 [HUDI-3528] Fix String convert issue and overwrite putAll method in TypedProperties.java (#4920)
8f1e4f5 is described below
commit 8f1e4f5b3e4e32e34f98191abb475f95f3690390
Author: stayrascal <st...@users.noreply.github.com>
AuthorDate: Mon Feb 28 23:45:47 2022 +0800
[HUDI-3528] Fix String convert issue and overwrite putAll method in TypedProperties.java (#4920)
---
.../apache/hudi/common/config/TypedProperties.java | 14 +++++++++-
.../common/properties/TestTypedProperties.java | 31 +++++++++++++++++++++-
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/config/TypedProperties.java b/hudi-common/src/main/java/org/apache/hudi/common/config/TypedProperties.java
index 4dbb0bc..6639e88 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/config/TypedProperties.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/config/TypedProperties.java
@@ -25,6 +25,7 @@ import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
@@ -63,11 +64,22 @@ public class TypedProperties extends Properties implements Serializable {
public Set<String> stringPropertyNames() {
Set<String> set = new LinkedHashSet<>();
for (Object key : this.keys) {
- set.add((String) key);
+ if (key instanceof String) {
+ set.add((String) key);
+ }
}
return set;
}
+ public synchronized void putAll(Properties t) {
+ for (Map.Entry<?, ?> e : t.entrySet()) {
+ if (!containsKey(String.valueOf(e.getKey()))) {
+ keys.add(e.getKey());
+ }
+ super.put(e.getKey(), e.getValue());
+ }
+ }
+
@Override
public synchronized Object put(Object key, Object value) {
keys.remove(key);
diff --git a/hudi-common/src/test/java/org/apache/hudi/common/properties/TestTypedProperties.java b/hudi-common/src/test/java/org/apache/hudi/common/properties/TestTypedProperties.java
index 3350ae5..a3ba13e 100644
--- a/hudi-common/src/test/java/org/apache/hudi/common/properties/TestTypedProperties.java
+++ b/hudi-common/src/test/java/org/apache/hudi/common/properties/TestTypedProperties.java
@@ -99,8 +99,37 @@ public class TestTypedProperties {
properties.put("key9", "true");
TypedProperties typedProperties = new TypedProperties(properties);
+ assertTypeProperties(typedProperties, 0);
+ }
+
+ @Test
+ void testPutAllProperties() {
+ Properties firstProp = new TypedProperties();
+ firstProp.put("key0", "true");
+ firstProp.put("key1", "false");
+ firstProp.put("key2", "true");
+
+ TypedProperties firstProperties = new TypedProperties(firstProp);
+ assertTypeProperties(firstProperties, 0);
+
+ TypedProperties secondProperties = new TypedProperties();
+ secondProperties.put("key3", "true");
+ secondProperties.put("key4", "false");
+ secondProperties.put("key5", "true");
+ assertTypeProperties(secondProperties, 3);
+
+ TypedProperties thirdProperties = new TypedProperties();
+ thirdProperties.putAll(firstProp);
+ thirdProperties.putAll(secondProperties);
+
+ assertEquals(3, firstProp.stringPropertyNames().size());
+ assertEquals(3, secondProperties.stringPropertyNames().size());
+ assertEquals(6, thirdProperties.stringPropertyNames().size());
+ }
+
+ private void assertTypeProperties(TypedProperties typedProperties, int start) {
String[] props = typedProperties.stringPropertyNames().toArray(new String[0]);
- for (int i = 0; i < props.length; i++) {
+ for (int i = start; i < props.length; i++) {
assertEquals(String.format("key%d", i), props[i]);
}
}