yihua commented on code in PR #20886:
URL: https://github.com/apache/hudi/pull/20886#discussion_r4722791893


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##########
@@ -162,7 +173,16 @@ object HoodieCreateRecordUtils {
               HoodieRecordUtils.createHoodieRecord(processedRecord, hoodieKey,
                 config.getPayloadClass, recordLocation, isDelete)
             }
-            hoodieRecord
+            if (movedTo.isDefined) {
+              val deleteRecord = 
HoodieRecordUtils.generateEmptyAvroRecord(readKey, OrderingValues.getDefault, 
config.getPayloadClass, null)
+              deleteRecord.setIgnoreIndexUpdate(true)

Review Comment:
   Fixed: the delete of a move now skips the record level index update only 
when the partitioned index is off, since a partitioned index keys an entry by 
the partition too and the delete has to remove the old partition's entry. A new 
UPDATE test moves a record of a table without a record key under the 
partitioned and the global index and checks that the index holds one entry per 
row, in the row's partition.
   



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestUpdateTable.scala:
##########
@@ -588,6 +590,154 @@ class TestUpdateTable extends HoodieSparkSqlTestBase {
     }
   }
 
+  test("Test Update Table moves a record to the partition it gives it in a 
table without a record key") {
+    withRecordType()(withTempDir { tmp =>
+      Seq("cow", "mor").foreach { tableType =>
+        val tableName = generateTableName
+        val tablePath = s"${tmp.getCanonicalPath}/$tableName"
+        spark.sql(
+          s"""
+             | create table $tableName (id int, name string, dep string) using 
hudi
+             | tblproperties (type = '$tableType')
+             | partitioned by (dep)
+             | location '$tablePath'
+           """.stripMargin)
+        spark.sql(s"insert into $tableName values (1, 'a1', 'd1'), (2, 'a2', 
'd1'), (3, 'a3', 'd2')")
+
+        // The compaction is left to the end of the test
+        withSQLConf(HoodieCompactionConfig.INLINE_COMPACT.key -> "false") {
+          // id 1 moves to a new partition and id 2 to one that holds a 
record, id 3 stays
+          spark.sql(s"update $tableName set dep = 'd3', name = 'a1u' where id 
= 1")
+          spark.sql(s"update $tableName set dep = 'd2' where id = 2")
+          spark.sql(s"update $tableName set name = 'a3u' where id = 3")
+          checkPartitionedRows(tableName, "dep")(Seq(1, "a1u", "d3"), Seq(2, 
"a2", "d2"), Seq(3, "a3u", "d2"))
+
+          // A statement that moves some of the records it updates
+          spark.sql(s"update $tableName set dep = if(id = 2, 'd1', dep), name 
= concat(name, 'v') where id in (1, 2)")
+        }
+        val expected = Seq(Seq(1, "a1uv", "d3"), Seq(2, "a2v", "d1"), Seq(3, 
"a3u", "d2"))
+        checkPartitionedRows(tableName, "dep")(expected: _*)
+        if (tableType == "mor") {
+          compactAndCheck(tableName)
+          checkPartitionedRows(tableName, "dep")(expected: _*)
+        }
+      }
+    })
+  }
+
+  test("Test Update Table moves a record across partitions only when its 
update applies under event time ordering") {

Review Comment:
   Done: UPDATE and MERGE INTO now each have an arm where the update has the 
same ordering value as the record and moves it, and a commit time ordering 
table with an ordering field moves a record whose update has a lower ordering 
value.
   



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