You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by yi...@apache.org on 2023/03/13 17:17:48 UTC

[hudi] branch master updated: [HUDI-5713] Add advanced property for configs (#7869)

This is an automated email from the ASF dual-hosted git repository.

yihua 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 ca76bc5788b [HUDI-5713] Add advanced property for configs (#7869)
ca76bc5788b is described below

commit ca76bc5788bf807ddc97e6614460bc09f6730e2b
Author: Jon Vexler <jb...@gmail.com>
AuthorDate: Mon Mar 13 10:17:37 2023 -0700

    [HUDI-5713] Add advanced property for configs (#7869)
    
    Adds the ability to mark a config as advanced so users don't need to care about them in most of the cases.
    
    Co-authored-by: Jonathan Vexler <=>
    Co-authored-by: Lokesh Jain <lj...@apache.org>
    Co-authored-by: Y Ethan Guo <et...@gmail.com>
---
 .../apache/hudi/common/config/ConfigProperty.java  | 38 +++++++++++++++-------
 .../hudi/common/config/TestConfigProperty.java     | 10 ++++++
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/hudi-common/src/main/java/org/apache/hudi/common/config/ConfigProperty.java b/hudi-common/src/main/java/org/apache/hudi/common/config/ConfigProperty.java
index 364fc4203a8..b5c8e5b841b 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/config/ConfigProperty.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/config/ConfigProperty.java
@@ -55,6 +55,8 @@ public class ConfigProperty<T> implements Serializable {
 
   private final Set<String> validValues;
 
+  private final boolean advanced;
+
   private final String[] alternatives;
 
   // provide the ability to infer config value based on other configs
@@ -63,7 +65,7 @@ public class ConfigProperty<T> implements Serializable {
   ConfigProperty(String key, T defaultValue, String docOnDefaultValue, String doc,
                  Option<String> sinceVersion, Option<String> deprecatedVersion,
                  Option<Function<HoodieConfig, Option<T>>> inferFunc, Set<String> validValues,
-                 String... alternatives) {
+                 boolean advanced, String... alternatives) {
     this.key = Objects.requireNonNull(key);
     this.defaultValue = defaultValue;
     this.docOnDefaultValue = docOnDefaultValue;
@@ -72,6 +74,7 @@ public class ConfigProperty<T> implements Serializable {
     this.deprecatedVersion = deprecatedVersion;
     this.inferFunction = inferFunc;
     this.validValues = validValues;
+    this.advanced = advanced;
     this.alternatives = alternatives;
   }
 
@@ -127,34 +130,45 @@ public class ConfigProperty<T> implements Serializable {
     return Arrays.asList(alternatives);
   }
 
+  public boolean isAdvanced() {
+    return advanced;
+  }
+
   public ConfigProperty<T> withDocumentation(String doc) {
     Objects.requireNonNull(doc);
-    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, deprecatedVersion, inferFunction, validValues, alternatives);
+    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, deprecatedVersion, inferFunction, validValues, advanced, alternatives);
   }
 
   public ConfigProperty<T> withValidValues(String... validValues) {
     Objects.requireNonNull(validValues);
-    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, deprecatedVersion, inferFunction, new HashSet<>(Arrays.asList(validValues)), alternatives);
+    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, deprecatedVersion, inferFunction, new HashSet<>(Arrays.asList(validValues)), advanced, alternatives);
   }
 
   public ConfigProperty<T> withAlternatives(String... alternatives) {
     Objects.requireNonNull(alternatives);
-    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, deprecatedVersion, inferFunction, validValues, alternatives);
+    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, deprecatedVersion, inferFunction, validValues, advanced, alternatives);
   }
 
   public ConfigProperty<T> sinceVersion(String sinceVersion) {
     Objects.requireNonNull(sinceVersion);
-    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, Option.of(sinceVersion), deprecatedVersion, inferFunction, validValues, alternatives);
+    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, Option.of(sinceVersion), deprecatedVersion, inferFunction, validValues, advanced, alternatives);
   }
 
   public ConfigProperty<T> deprecatedAfter(String deprecatedVersion) {
     Objects.requireNonNull(deprecatedVersion);
-    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, Option.of(deprecatedVersion), inferFunction, validValues, alternatives);
+    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, Option.of(deprecatedVersion), inferFunction, validValues, advanced, alternatives);
   }
 
   public ConfigProperty<T> withInferFunction(Function<HoodieConfig, Option<T>> inferFunction) {
     Objects.requireNonNull(inferFunction);
-    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, deprecatedVersion, Option.of(inferFunction), validValues, alternatives);
+    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, deprecatedVersion, Option.of(inferFunction), validValues, advanced, alternatives);
+  }
+
+  /**
+   * Marks the config as an advanced config.
+   */
+  public ConfigProperty<T> markAdvanced() {
+    return new ConfigProperty<>(key, defaultValue, docOnDefaultValue, doc, sinceVersion, deprecatedVersion, inferFunction, validValues, true, alternatives);
   }
 
   /**
@@ -171,8 +185,8 @@ public class ConfigProperty<T> implements Serializable {
   @Override
   public String toString() {
     return String.format(
-        "Key: '%s' , default: %s description: %s since version: %s deprecated after: %s)",
-        key, defaultValue, doc, sinceVersion.isPresent() ? sinceVersion.get() : "version is not defined",
+        "Key: '%s' , default: %s , isAdvanced: %s , description: %s since version: %s deprecated after: %s)",
+        key, defaultValue, advanced, doc, sinceVersion.isPresent() ? sinceVersion.get() : "version is not defined",
         deprecatedVersion.isPresent() ? deprecatedVersion.get() : "version is not defined");
   }
 
@@ -194,7 +208,7 @@ public class ConfigProperty<T> implements Serializable {
     public <T> ConfigProperty<T> defaultValue(T value, String docOnDefaultValue) {
       Objects.requireNonNull(value);
       Objects.requireNonNull(docOnDefaultValue);
-      ConfigProperty<T> configProperty = new ConfigProperty<>(key, value, docOnDefaultValue, "", Option.empty(), Option.empty(), Option.empty(), Collections.emptySet());
+      ConfigProperty<T> configProperty = new ConfigProperty<>(key, value, docOnDefaultValue, "", Option.empty(), Option.empty(), Option.empty(), Collections.emptySet(), false);
       return configProperty;
     }
 
@@ -204,8 +218,8 @@ public class ConfigProperty<T> implements Serializable {
 
     public ConfigProperty<String> noDefaultValue(String docOnDefaultValue) {
       ConfigProperty<String> configProperty = new ConfigProperty<>(key, null, docOnDefaultValue, "", Option.empty(),
-          Option.empty(), Option.empty(), Collections.emptySet());
+          Option.empty(), Option.empty(), Collections.emptySet(), false);
       return configProperty;
     }
   }
-}
\ No newline at end of file
+}
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 584edfe60b9..3868c4fb445 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
@@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test;
 import java.util.Properties;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -161,4 +162,13 @@ public class TestConfigProperty extends HoodieConfig {
     setDefaults(this.getClass().getName());
     assertEquals(4, getProps().size());
   }
+
+  @Test
+  public void testAdvancedValue() {
+    assertFalse(FAKE_BOOLEAN_CONFIG.isAdvanced());
+    assertFalse(FAKE_BOOLEAN_CONFIG_NO_DEFAULT.isAdvanced());
+
+    assertTrue(FAKE_BOOLEAN_CONFIG.markAdvanced().isAdvanced());
+    assertTrue(FAKE_BOOLEAN_CONFIG_NO_DEFAULT.markAdvanced().isAdvanced());
+  }
 }