You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/11/05 06:12:48 UTC

[GitHub] [hudi] xushiyan commented on a change in pull request #3359: [HUDI-2242] Add configuration inference logic for few options

xushiyan commented on a change in pull request #3359:
URL: https://github.com/apache/hudi/pull/3359#discussion_r743404551



##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/config/HoodieLockConfig.java
##########
@@ -160,9 +161,17 @@
   public static final ConfigProperty<String> ZK_LOCK_KEY = ConfigProperty
       .key(ZK_LOCK_KEY_PROP_KEY)
       .noDefaultValue()
+      .withInferFunction(p -> {
+        if (p.contains(HoodieWriteConfig.TBL_NAME)) {
+          return Option.of(p.getString(HoodieWriteConfig.TBL_NAME));
+        } else {
+          return Option.empty();

Review comment:
       can do 1-liner here `Option.ofNullable(props.getStringOrDefault(, null)`

##########
File path: hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/DataSourceOptions.scala
##########
@@ -273,8 +278,26 @@ object DataSourceWriteOptions {
    */
   val HIVE_STYLE_PARTITIONING = KeyGeneratorOptions.HIVE_STYLE_PARTITIONING_ENABLE
 
-  val KEYGENERATOR_CLASS_NAME = ConfigProperty.key("hoodie.datasource.write.keygenerator.class")
+  /**
+    * Key generator class, that implements will extract the key out of incoming record
+    *
+    */
+  val keyGeneraterInferFunc = DataSourceOptionsHelper.scalaFunctionToJavaFunction((p: HoodieConfig) => {
+    if (!p.contains(PARTITIONPATH_FIELD)) {
+      Option.of(classOf[NonpartitionedKeyGenerator].getName)
+    } else {
+      val numOfPartFields = p.getString(PARTITIONPATH_FIELD).split(",").length
+      if (numOfPartFields == 1) {
+        Option.of(classOf[SimpleKeyGenerator].getName)
+      } else {
+        Option.of(classOf[ComplexKeyGenerator].getName)
+      }
+    }
+  })
+  val KEYGENERATOR_CLASS_NAME: ConfigProperty[String] = ConfigProperty
+    .key("hoodie.datasource.write.keygenerator.class")
     .defaultValue(classOf[SimpleKeyGenerator].getName)
+    .withInferFunction(keyGeneraterInferFunc)

Review comment:
       shall we overload `withInferFunction()` to take in scala func too? then no need to convert every time




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org