yihua commented on code in PR #10615:
URL: https://github.com/apache/hudi/pull/10615#discussion_r1563151868
##########
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:
Flink writer should provide the correct partition field write config. The
query side may have some gaps.
Created [HUDI-7613](https://issues.apache.org/jira/browse/HUDI-7613) as a
follow-up.
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieWriterUtils.scala:
##########
@@ -201,8 +201,26 @@ object HoodieWriterUtils {
diffConfigs.append(s"KeyGenerator:\t$datasourceKeyGen\t$tableConfigKeyGen\n")
}
+ // Please note that the validation of partition path fields needs the
key generator class
+ // for the table, since the custom key generator expects a different
format of
+ // the value of the write config
"hoodie.datasource.write.partitionpath.field"
+ // e.g., "col:simple,ts:timestamp", whereas the table config
"hoodie.table.partition.fields"
+ // in hoodie.properties stores "col,ts".
+ // The "params" here may only contain the write config of partition
path field,
+ // so we need to pass in the validated key generator class name.
+ val validatedKeyGenClassName = if (tableConfigKeyGen != null) {
Review Comment:
Only the `hoodie.datasource.write.partitionpath.field` takes effect in the
writer path. Before the fix, the write config is automatically set by the SQL
writer based on the value of table config `hoodie.table.partition.fields`.
##########
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:
It fails with the error message `Unable to find field names for partition
path in proper format` in the `CustomKeyGenerator` indicating that the config
is not set properly.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]