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


##########
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:
   **blocker:** The move decision compares ordering values with `>=` 
(`MergeIntoHoodieTableCommand.scala:1311`), but this test and 
`TestMergeIntoTableWithNonRecordKeyField.scala:558` use only strictly lower or 
higher values. If it became `>`, a tie would write the new partition value into 
the record in place in the old partition, and no test would fail. Could we add 
an equal-ordering-value arm for both UPDATE and MERGE INTO, plus one 
`COMMIT_TIME_ORDERING` table with an ordering field where a lower value still 
moves?



##########
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:
   **blocker:** This flag makes `RecordIndexMapper` skip the delete at the old 
location. That is right for a global RLI, where the insert overwrites the key's 
entry, but a partitioned RLI keys entries by (key, partition), so (key, old 
partition) is never removed and the index keeps a stale entry. The only other 
use of the flag, `HoodieIndexUtils.java:553`, is reachable only with a global 
index. I traced this and have not run it. Could the flag be set only when the 
RLI is global, with an UPDATE move test on a keyless table with the partitioned 
RLI enabled?



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