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/01/07 21:20:34 UTC

[hudi] branch master updated: [HUDI-3185] HoodieConfig#getBoolean should return false when default not set (#4536)

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 518488c  [HUDI-3185] HoodieConfig#getBoolean should return false when default not set (#4536)
518488c is described below

commit 518488c6334e3d11dde959dd2080f6b6ba2372eb
Author: Sagar Sumit <sa...@gmail.com>
AuthorDate: Sat Jan 8 02:50:11 2022 +0530

    [HUDI-3185] HoodieConfig#getBoolean should return false when default not set (#4536)
    
    Remove unnecessary config
---
 .../org/apache/hudi/common/config/HoodieConfig.java   |  3 +++
 .../apache/hudi/common/config/TestConfigProperty.java | 19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/hudi-common/src/main/java/org/apache/hudi/common/config/HoodieConfig.java b/hudi-common/src/main/java/org/apache/hudi/common/config/HoodieConfig.java
index 997f8a3..c051165 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/config/HoodieConfig.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/config/HoodieConfig.java
@@ -146,6 +146,9 @@ public class HoodieConfig implements Serializable {
   }
 
   public <T> Boolean getBoolean(ConfigProperty<T> configProperty) {
+    if (configProperty.hasDefaultValue()) {
+      return getBooleanOrDefault(configProperty);
+    }
     Option<Object> rawValue = getRawValue(configProperty);
     return rawValue.map(v -> Boolean.parseBoolean(v.toString())).orElse(null);
   }
diff --git a/hudi-common/src/test/java/org/apache/hudi/common/config/TestConfigProperty.java b/hudi-common/src/test/java/org/apache/hudi/common/config/TestConfigProperty.java
index 5ca48f1..6cbb9bd 100644
--- a/hudi-common/src/test/java/org/apache/hudi/common/config/TestConfigProperty.java
+++ b/hudi-common/src/test/java/org/apache/hudi/common/config/TestConfigProperty.java
@@ -40,6 +40,11 @@ public class TestConfigProperty extends HoodieConfig {
       .defaultValue("false")
       .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
       .key("test.fake.integer.config")
       .defaultValue(0)
@@ -58,12 +63,24 @@ public class TestConfigProperty extends HoodieConfig {
     hoodieConfig.setValue(FAKE_STRING_CONFIG, "5");
     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");
     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
   public void testGetOrDefault() {
     Properties props = new Properties();
     props.put("test.unknown.config", "abc");