TengHuo commented on code in PR #6049:
URL: https://github.com/apache/hudi/pull/6049#discussion_r920877138


##########
hudi-spark-datasource/hudi-spark-common/src/main/java/org/apache/hudi/HoodieDatasetBulkInsertHelper.java:
##########
@@ -97,8 +96,31 @@ public static Dataset<Row> 
prepareHoodieDatasetForBulkInsert(SQLContext sqlConte
       // simple fields for both record key and partition path: can directly 
use withColumn
       String partitionPathField = 
keyGeneratorClass.equals(SimpleKeyGenerator.class.getName()) ? 
partitionPathFields :
           partitionPathFields.substring(partitionPathFields.indexOf(":") + 1);
-      rowDatasetWithRecordKeysAndPartitionPath = 
rows.withColumn(HoodieRecord.RECORD_KEY_METADATA_FIELD, 
functions.col(recordKeyFields).cast(DataTypes.StringType))
-          .withColumn(HoodieRecord.PARTITION_PATH_METADATA_FIELD, 
functions.col(partitionPathField).cast(DataTypes.StringType));
+
+      // TODO(HUDI-3993) cleanup duplication
+      String tableName = 
properties.getString(HoodieWriteConfig.TBL_NAME.key());
+      String partitionPathDecorationUDFName = PARTITION_PATH_UDF_FN + 
tableName;
+
+      boolean shouldURLEncodePartitionPath = 
config.shouldURLEncodePartitionPath();
+      boolean isHiveStylePartitioned = config.isHiveStylePartitioningEnabled();
+
+      if (shouldURLEncodePartitionPath || isHiveStylePartitioned) {
+        sqlContext.udf().register(
+            partitionPathDecorationUDFName,
+            (UDF1<String, String>) partitionPathValue ->
+                KeyGenUtils.handlePartitionPathDecoration(partitionPathField, 
partitionPathValue,
+                    shouldURLEncodePartitionPath, isHiveStylePartitioned),
+            DataTypes.StringType);
+
+        rowDatasetWithRecordKeysAndPartitionPath =
+            rows.withColumn(HoodieRecord.RECORD_KEY_METADATA_FIELD, 
functions.col(recordKeyFields).cast(DataTypes.StringType))

Review Comment:
   In `ComplexKeyGenerator.getRecordKey(Row row)`, we setup `prefixFieldName` 
as `true` in method `RowKeyGeneratorHelper.getRecordKeyFromRow(row, 
getRecordKeyFields(), recordKeySchemaInfo, true)`, so the record key will have 
a prefix, which is record key field name, when we use `ComplexKeyGenerator`.
   
   As I understand here, we use `withColumn` here for `recordKeyFields`, then 
we will get the same value in `RECORD_KEY_METADATA_FIELD` as the original 
`recordKeyFields`, so no prefix when key generator is `ComplexKeyGenerator`. 
Will it cause problem?



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

Reply via email to