yihua commented on code in PR #12201:
URL: https://github.com/apache/hudi/pull/12201#discussion_r1828451083
##########
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/payload/ExpressionPayload.scala:
##########
@@ -164,6 +163,34 @@ class ExpressionPayload(@transient record: GenericRecord,
}
}
+ private def doRecordMerge(incomingRecord: GenericRecord,
+ existingRecord: IndexedRecord,
+ schema: Schema,
+ properties: Properties): HOption[IndexedRecord] = {
+ val originalPayload = properties.getProperty(PAYLOAD_ORIGINAL_AVRO_PAYLOAD)
+ if
(originalPayload.equals(classOf[OverwriteWithLatestAvroPayload].getName)) {
+ HOption.of(incomingRecord)
+ } else if
(originalPayload.equals(classOf[DefaultHoodieRecordPayload].getName)) {
+ if (needUpdatingPersistedRecord(existingRecord, incomingRecord,
properties)) {
+ HOption.of(incomingRecord)
+ } else {
+ HOption.of(existingRecord)
+ }
+ } else {
+ val orderingField = ConfigUtils.getOrderingField(properties)
+ if (StringUtils.isNullOrEmpty(orderingField)) {
+ HOption.of(incomingRecord)
+ } else {
+ val consistentLogicalTimestampEnabled =
properties.getProperty(KeyGeneratorOptions.KEYGENERATOR_CONSISTENT_LOGICAL_TIMESTAMP_ENABLED.key,
+
KeyGeneratorOptions.KEYGENERATOR_CONSISTENT_LOGICAL_TIMESTAMP_ENABLED.defaultValue).toBoolean
+ val incomingRecordPayload =
HoodieRecordUtils.loadPayload(originalPayload, incomingRecord,
+ HoodieAvroUtils.getNestedFieldVal(incomingRecord, orderingField,
true, consistentLogicalTimestampEnabled)
+ .asInstanceOf[Comparable[_]]).asInstanceOf[HoodieRecordPayload[_
<: HoodieRecordPayload[_]]]
+ incomingRecordPayload.combineAndGetUpdateValue(existingRecord, schema,
properties)
Review Comment:
Could we just cache `incomingRecordPayload` for all payload classes and
invoke `incomingRecordPayload.combineAndGetUpdateValue` for
`OverwriteWithLatestAvroPayload` and `DefaultHoodieRecordPayload` too?
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/TestMergeIntoTable2.scala:
##########
@@ -1030,4 +1031,97 @@ class TestMergeIntoTable2 extends HoodieSparkSqlTestBase
{
checkAnswer(s"show partitions $destTable")(Seq("dt=2022-09-26"))
}
}
+
+
+
+ test("Test MergeInto with various payloads") {
Review Comment:
Test both COW and MOR tables. For MOR, set
`hoodie.merge.small.file.group.candidates.limit=0`.
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/TestMergeIntoTable2.scala:
##########
@@ -1030,4 +1031,97 @@ class TestMergeIntoTable2 extends HoodieSparkSqlTestBase
{
checkAnswer(s"show partitions $destTable")(Seq("dt=2022-09-26"))
}
}
+
+
+
Review Comment:
Remove redundant empty lines
--
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]