[HUDI-3730] Improve meta sync class design and hierarchies (#5854)
* [HUDI-3730] Improve meta sync class design and hierarchies (#5754) * Implements class design proposed in RFC-55 Co-authored-by: jian.feng <fengjian428@gmial.com> Co-authored-by: jian.feng <jian.feng@shopee.com>
This commit is contained in:
@@ -21,6 +21,7 @@ package org.apache.hudi.common.config;
|
||||
import org.apache.hadoop.fs.FSDataInputStream;
|
||||
import org.apache.hudi.common.util.Option;
|
||||
import org.apache.hudi.common.util.ReflectionUtils;
|
||||
import org.apache.hudi.common.util.StringUtils;
|
||||
import org.apache.hudi.exception.HoodieException;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
@@ -29,6 +30,7 @@ import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -133,6 +135,14 @@ public class HoodieConfig implements Serializable {
|
||||
return rawValue.map(Object::toString).orElse(null);
|
||||
}
|
||||
|
||||
public <T> List<String> getSplitStrings(ConfigProperty<T> configProperty) {
|
||||
return getSplitStrings(configProperty, ",");
|
||||
}
|
||||
|
||||
public <T> List<String> getSplitStrings(ConfigProperty<T> configProperty, String delimiter) {
|
||||
return StringUtils.split(getString(configProperty), delimiter);
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return props.getProperty(key);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,12 @@ public class TypedProperties extends Properties implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public void setPropertyIfNonNull(String key, Object value) {
|
||||
if (value != null) {
|
||||
setProperty(key, value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String key) {
|
||||
Object oval = super.get(key);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package org.apache.hudi.common.util;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -65,6 +66,18 @@ public class StringUtils {
|
||||
return org.apache.hadoop.util.StringUtils.join(separator, array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper of {@link java.lang.String#join(CharSequence, Iterable)}.
|
||||
*
|
||||
* Allow return {@code null} when {@code Iterable} is {@code null}.
|
||||
*/
|
||||
public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) {
|
||||
if (elements == null) {
|
||||
return null;
|
||||
}
|
||||
return String.join(delimiter, elements);
|
||||
}
|
||||
|
||||
public static String toHexString(byte[] bytes) {
|
||||
StringBuilder sb = new StringBuilder(bytes.length * 2);
|
||||
for (byte b : bytes) {
|
||||
@@ -77,6 +90,9 @@ public class StringUtils {
|
||||
return str == null || str.length() == 0;
|
||||
}
|
||||
|
||||
public static boolean nonEmpty(String str) {
|
||||
return !isNullOrEmpty(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given string if it is non-null; the empty string otherwise.
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
@@ -45,6 +46,14 @@ public class TestStringUtils {
|
||||
assertNotEquals(null, StringUtils.join(STRINGS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringJoinWithJavaImpl() {
|
||||
assertNull(StringUtils.join(",", null));
|
||||
assertEquals("", String.join(",", Collections.singletonList("")));
|
||||
assertEquals(",", String.join(",", Arrays.asList("", "")));
|
||||
assertEquals("a,", String.join(",", Arrays.asList("a", "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringNullToEmpty() {
|
||||
String str = "This is a test";
|
||||
|
||||
Reference in New Issue
Block a user