yihua opened a new pull request, #20850: URL: https://github.com/apache/hudi/pull/20850
### Describe the issue this Pull Request addresses closes #20827 Spark SQL MERGE INTO does not apply the first matched clause that holds: the payload checks every UPDATE clause before the DELETE clause, and the clauses reach the payload in an unordered `Map` once there are more than four of them (with the last of two equal conditions winning). ### Summary and Changelog `MergeIntoHoodieTableCommand#serializeConditionalAssignments` now passes the clauses in the order written, as a `ListMap` that keeps the first clause for a repeated condition. An UPDATE clause written after the DELETE clause also requires the delete condition not to hold (`AND NOT coalesce(delete_condition, false)`), so the payload's update-then-delete evaluation gives the same result as checking the clauses in order. INSERT clauses share the serialization, so NOT MATCHED clauses also keep their order and the first of two equal conditions now wins. The payload itself is unchanged. Both the Spark 3 and Spark 4 copies of the command get the change. Two new cases in `TestMergeIntoTable2` cover DELETE before and after UPDATE, and six UPDATE clauses with a repeated condition, on COW and MOR tables. On master they fail with `Expected Array([2,u2,22.0,1001]), but got Array([1,u1,11.0,1001], [2,u2,22.0,1001])` and `Expected Array([1,c2,11.0,1001]), but got Array([1,c6,11.0,1001])`. The import line of the command conflicts textually with #20820 and #20821, and the new tests append to `TestMergeIntoTable2` as #20832 does; the rebase is mechanical either way. ### Impact MERGE INTO statements whose matched clauses overlap now follow SQL semantics. Statements with at most four clauses and no UPDATE after the DELETE behave as before. ### 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]
