You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "nsivabalan (via GitHub)" <gi...@apache.org> on 2023/04/03 20:13:36 UTC

[GitHub] [hudi] nsivabalan commented on a diff in pull request #8107: [HUDI-5514] Adding auto generation of record keys support to Hudi/Spark

nsivabalan commented on code in PR #8107:
URL: https://github.com/apache/hudi/pull/8107#discussion_r1156413723


##########
hudi-client/hudi-spark-client/src/main/scala/org/apache/hudi/HoodieDatasetBulkInsertHelper.scala:
##########
@@ -82,9 +86,19 @@ object HoodieDatasetBulkInsertHelper
           val keyGenerator =
             ReflectionUtils.loadClass(keyGeneratorClassName, new TypedProperties(config.getProps))
               .asInstanceOf[SparkKeyGeneratorInterface]
+          val partitionId = TaskContext.getPartitionId()
+          var rowId = 0
 
           iter.map { row =>
-            val recordKey = keyGenerator.getRecordKey(row, schema)
+            // auto generate record keys if needed
+            val recordKey = if (autoGenerateRecordKeys) {
+              val recKey = HoodieRecord.generateSequenceId(instantTime, partitionId, rowId)
+              rowId += 1
+              UTF8String.fromString(recKey)
+            }
+            else { // else use key generator to fetch record key
+              keyGenerator.getRecordKey(row, schema)

Review Comment:
   for normal ingestion, we don't use empty string. I will respond to your question elsewhere (where we return empty string). its not very apparent. 
   



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