zhedoubushishi commented on a change in pull request #2833:
URL: https://github.com/apache/hudi/pull/2833#discussion_r631570523
##########
File path:
hudi-common/src/main/java/org/apache/hudi/common/config/DefaultHoodieConfig.java
##########
@@ -44,8 +56,93 @@ public static void setDefaultOnCondition(Properties props,
boolean condition, De
}
}
+ public static <T> void set(Properties props, ConfigOption<T> cfg, String
val) {
+ props.setProperty(cfg.key(), val);
+ }
+
+ public static <T> void setDefaultValue(Properties props, ConfigOption<T>
configOption) {
+ if (!contains(props, configOption)) {
+ Option<String> inferValue = Option.empty();
+ if (configOption.getInferFunc() != null) {
+ inferValue = (Option<String>) configOption.getInferFunc().apply(props);
+ }
+ props.setProperty(configOption.key(), inferValue.isPresent() ?
inferValue.get() : configOption.defaultValue().toString());
+ }
+ }
+
+ public static <T> void setDefaultValue(Map<String, String> props,
ConfigOption<T> configOption) {
+ if (!contains(props, configOption)) {
+ Option<String> inferValue = Option.empty();
+ if (configOption.getInferFunc() != null) {
+ inferValue = (Option<String>) configOption.getInferFunc().apply(props);
+ }
+ props.put(configOption.key(), inferValue.isPresent() ? inferValue.get()
: configOption.defaultValue().toString());
+ }
+ }
+
+ public static <T> boolean contains(Map props, ConfigOption<T> configOption) {
+ if (props.containsKey(configOption.key())) {
+ return true;
+ }
+ return
Arrays.stream(configOption.getAlternatives()).anyMatch(props::containsKey);
+ }
+
+ public static <T> Option<Object> getRawValue(Map props, ConfigOption<T>
configOption) {
+ if (props.containsKey(configOption.key())) {
+ return Option.ofNullable(props.get(configOption.key()));
+ }
+ for (String alternative : configOption.getAlternatives()) {
+ if (props.containsKey(alternative)) {
+ LOG.warn(String.format("The configuration key '%s' has been deprecated
"
+ + "and may be removed in the future. Please use the new key
'%s' instead.",
+ alternative, configOption.key()));
+ return Option.ofNullable(props.get(alternative));
+ }
+ }
+ return Option.empty();
+ }
+
+ public static <T> String getString(Map props, ConfigOption<T> configOption) {
+ Option<Object> rawValue = getRawValue(props, configOption);
+ return rawValue.map(Object::toString).orElse(null);
Review comment:
Here I tried to keep the same logic as before. Previously,
```Properties.getProperty(String key)``` would return null if key does not
exist. ```Properties.getProperty()``` is indirectly called in many places, I
suspect it could break something if we change the logic to throw an exception
when key is not found.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]