You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "codope (via GitHub)" <gi...@apache.org> on 2024/04/04 07:30:00 UTC

Re: [PR] [HUDI-7378] Fix Spark SQL DML with custom key generator [hudi]

codope commented on code in PR #10615:
URL: https://github.com/apache/hudi/pull/10615#discussion_r1551075779


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/ProvidesHoodieConfig.scala:
##########
@@ -528,6 +536,40 @@ object ProvidesHoodieConfig {
       filterNullValues(overridingOpts)
   }
 
+  /**
+   * @param tableConfigKeyGeneratorClassName     key generator class name in the table config.
+   * @param partitionFieldNamesWithoutKeyGenType partition field names without key generator types
+   *                                             from the table config.
+   * @param catalogTable                         HoodieCatalogTable instance to fetch table properties.
+   * @return the write config value to set for "hoodie.datasource.write.partitionpath.field".
+   */
+  def getPartitionPathFieldWriteConfig(tableConfigKeyGeneratorClassName: String,
+                                       partitionFieldNamesWithoutKeyGenType: String,
+                                       catalogTable: HoodieCatalogTable): String = {
+    if (StringUtils.isNullOrEmpty(tableConfigKeyGeneratorClassName)) {
+      partitionFieldNamesWithoutKeyGenType
+    } else {

Review Comment:
   Should we instead directly infer from the passed string `tableConfigKeyGeneratorClassName`? I mean if the string has no `:` then return `partitionFieldNamesWithoutKeyGenType`. I am not following why `tableConfigKeyGeneratorClassName` being null or empty means partition field names are without keygen type. Suppose, in a future release we drop the keygen config from table properties, then will this hold true?



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/ProvidesHoodieConfig.scala:
##########
@@ -528,6 +536,40 @@ object ProvidesHoodieConfig {
       filterNullValues(overridingOpts)
   }
 
+  /**
+   * @param tableConfigKeyGeneratorClassName     key generator class name in the table config.
+   * @param partitionFieldNamesWithoutKeyGenType partition field names without key generator types
+   *                                             from the table config.
+   * @param catalogTable                         HoodieCatalogTable instance to fetch table properties.
+   * @return the write config value to set for "hoodie.datasource.write.partitionpath.field".
+   */
+  def getPartitionPathFieldWriteConfig(tableConfigKeyGeneratorClassName: String,
+                                       partitionFieldNamesWithoutKeyGenType: String,
+                                       catalogTable: HoodieCatalogTable): String = {
+    if (StringUtils.isNullOrEmpty(tableConfigKeyGeneratorClassName)) {
+      partitionFieldNamesWithoutKeyGenType
+    } else {
+      val writeConfigPartitionField = catalogTable.catalogProperties.get(PARTITIONPATH_FIELD.key())
+      val keyGenClass = ReflectionUtils.getClass(tableConfigKeyGeneratorClassName)
+      if (classOf[CustomKeyGenerator].equals(keyGenClass)
+        || classOf[CustomAvroKeyGenerator].equals(keyGenClass)) {
+        // For custom key generator, we have to take the write config value from
+        // "hoodie.datasource.write.partitionpath.field" which contains the key generator
+        // type, whereas the table config only contains the prtition field names without
+        // key generator types.
+        if (writeConfigPartitionField.isDefined) {
+          writeConfigPartitionField.get
+        } else {
+          log.warn("Write config \"hoodie.datasource.write.partitionpath.field\" is not set for "
+            + "custom key generator. This may fail the write operation.")
+          partitionFieldNamesWithoutKeyGenType

Review Comment:
   Should we then fail early if write is going to fail? Maybe, make it like a validation?



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