amrishlal commented on code in PR #8879:
URL: https://github.com/apache/hudi/pull/8879#discussion_r1224743963
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala:
##########
@@ -1195,18 +1214,108 @@ object HoodieSparkSqlWriter {
}
val sparkKeyGenerator =
HoodieSparkKeyGeneratorFactory.createKeyGenerator(keyGenProps).asInstanceOf[SparkKeyGeneratorInterface]
val targetStructType = if (shouldDropPartitionColumns)
dataFileStructType else writerStructType
+ val finalStructType = if (isPrepped) {
+ val fieldsToExclude =
HoodieRecord.HOODIE_META_COLUMNS_WITH_OPERATION.toArray()
+ StructType(targetStructType.fields.filterNot(field =>
fieldsToExclude.contains(field.name)))
+ } else {
+ targetStructType
+ }
// NOTE: To make sure we properly transform records
- val targetStructTypeRowWriter =
getCachedUnsafeRowWriter(sourceStructType, targetStructType)
+ val finalStructTypeRowWriter =
getCachedUnsafeRowWriter(sourceStructType, finalStructType)
it.map { sourceRow =>
- val recordKey = sparkKeyGenerator.getRecordKey(sourceRow,
sourceStructType)
- val partitionPath = sparkKeyGenerator.getPartitionPath(sourceRow,
sourceStructType)
- val key = new HoodieKey(recordKey.toString, partitionPath.toString)
- val targetRow = targetStructTypeRowWriter(sourceRow)
+ val (hoodieKey: HoodieKey, recordLocation:
Option[HoodieRecordLocation]) =
getKeyAndLocatorFromSparkRecord(sparkKeyGenerator, sourceRow, sourceStructType,
isPrepped)
- new HoodieSparkRecord(key, targetRow, dataFileStructType, false)
+ val finalRow = finalStructTypeRowWriter(sourceRow)
+ var hoodieSparkRecord = new HoodieSparkRecord(hoodieKey, finalRow,
dataFileStructType, false)
+ if (recordLocation.getOrElse(null) != null) {
+ hoodieSparkRecord.setCurrentLocation(recordLocation.get)
+ }
+ hoodieSparkRecord
}
}.toJavaRDD().asInstanceOf[JavaRDD[HoodieRecord[_]]]
}
}
+
+ private def getKeyAndLocatorFromAvroRecord(keyGenerator: BaseKeyGenerator,
avroRec: GenericRecord,
Review Comment:
Replaced with `getHoodieKeyAndMaybeLocationFromAvroRecord` and
`getHoodieKeyAndMaybeLocationFromSparkRecord`
--
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]