yihua opened a new pull request, #20820: URL: https://github.com/apache/hudi/pull/20820
### Describe the issue this Pull Request addresses closes #20818 A Spark SQL `MERGE INTO` without an update clause, on a table without an ordering field, is written as an insert, which never finds the target record. `WHEN MATCHED THEN DELETE` deletes nothing, and `WHEN NOT MATCHED THEN INSERT` inserts a source row again under a key the table already holds (or, on a table without a record key, inserts a matched source row as a new row). ### Summary and Changelog `MergeIntoHoodieTableCommand.getOperationType` now returns upsert whenever the table has a record key, or the statement has a matched clause, so the index lookup (or, without a record key, the join with the target) decides which clause applies. On a table without a record key, a statement with only not-matched clauses stays an insert and drops the source rows that match the table before the write. The same change is made in the `hudi-spark3-common` and `hudi-spark4-common` copies. New tests run a delete with and without a condition, an insert with and without a condition, and a delete with an insert, each without an update clause, on COW and MOR tables with and without a record key. They fail on master with the matched rows still present or inserted again. ### Impact An insert-only `MERGE INTO` on a table with a record key now does an index lookup. Source rows that share a record key in one such statement can end up as a single record, as they already do for a statement with an update clause (#20819 keeps a row that fails the insert condition from taking the place of one that passes). ### Risk Level low ### Documentation Update none ### Contributor's checklist - [ ] Read through [contributor's guide](https://hudi.apache.org/contribute/how-to-contribute) - [ ] Enough context is provided in the sections above - [ ] Adequate tests were added if applicable -- 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]
