[HUDI-3185] HoodieConfig#getBoolean should return false when default not set (#4536)
Remove unnecessary config
This commit is contained in:
@@ -146,6 +146,9 @@ public class HoodieConfig implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T> Boolean getBoolean(ConfigProperty<T> configProperty) {
|
public <T> Boolean getBoolean(ConfigProperty<T> configProperty) {
|
||||||
|
if (configProperty.hasDefaultValue()) {
|
||||||
|
return getBooleanOrDefault(configProperty);
|
||||||
|
}
|
||||||
Option<Object> rawValue = getRawValue(configProperty);
|
Option<Object> rawValue = getRawValue(configProperty);
|
||||||
return rawValue.map(v -> Boolean.parseBoolean(v.toString())).orElse(null);
|
return rawValue.map(v -> Boolean.parseBoolean(v.toString())).orElse(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ public class TestConfigProperty extends HoodieConfig {
|
|||||||
.defaultValue("false")
|
.defaultValue("false")
|
||||||
.withDocumentation("Fake config only for testing");
|
.withDocumentation("Fake config only for testing");
|
||||||
|
|
||||||
|
public static ConfigProperty<String> FAKE_BOOLEAN_CONFIG_NO_DEFAULT = ConfigProperty
|
||||||
|
.key("test.fake.boolean.config")
|
||||||
|
.noDefaultValue()
|
||||||
|
.withDocumentation("Fake config only for testing");
|
||||||
|
|
||||||
public static ConfigProperty<Integer> FAKE_INTEGER_CONFIG = ConfigProperty
|
public static ConfigProperty<Integer> FAKE_INTEGER_CONFIG = ConfigProperty
|
||||||
.key("test.fake.integer.config")
|
.key("test.fake.integer.config")
|
||||||
.defaultValue(0)
|
.defaultValue(0)
|
||||||
@@ -58,11 +63,23 @@ public class TestConfigProperty extends HoodieConfig {
|
|||||||
hoodieConfig.setValue(FAKE_STRING_CONFIG, "5");
|
hoodieConfig.setValue(FAKE_STRING_CONFIG, "5");
|
||||||
assertEquals(5, hoodieConfig.getInt(FAKE_STRING_CONFIG));
|
assertEquals(5, hoodieConfig.getInt(FAKE_STRING_CONFIG));
|
||||||
|
|
||||||
assertNull(hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG));
|
assertEquals(false, hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG));
|
||||||
hoodieConfig.setValue(FAKE_BOOLEAN_CONFIG, "true");
|
hoodieConfig.setValue(FAKE_BOOLEAN_CONFIG, "true");
|
||||||
assertEquals(true, hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG));
|
assertEquals(true, hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetBooleanShouldReturnFalseWhenDefaultValueFalseButNotSet() {
|
||||||
|
HoodieConfig hoodieConfig = new HoodieConfig();
|
||||||
|
assertEquals(false, hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetBooleanShouldReturnNullWhenNoDefaultValuePresent() {
|
||||||
|
HoodieConfig hoodieConfig = new HoodieConfig();
|
||||||
|
assertNull(hoodieConfig.getBoolean(FAKE_BOOLEAN_CONFIG_NO_DEFAULT));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetOrDefault() {
|
public void testGetOrDefault() {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
|
|||||||
Reference in New Issue
Block a user