yihua opened a new pull request, #20886: URL: https://github.com/apache/hudi/pull/20886
### Describe the issue this Pull Request addresses closes #20833 A MERGE INTO update clause can assign a partition column, as `UPDATE SET *` does, but the matched record is written back to the file group it was found in, so it stays in its old partition holding the new value. With a record key this also happens under a global index when the clause assigns a value other than the one the source row is looked up under, and UPDATE refuses every assignment to a partition field. ### Summary and Changelog Stacked on #20844, review that first: a record a global index moves lands in a small file group through the merge handle, which needs that fix. This PR supersedes #20838, which can be closed when this lands: it includes #20838's refusal, replaces the keyless refusal with the move, and keeps the refusal under an index that does not move records. If #20838 merges first, this PR takes back its keyless refusal. - With a record key and a global index that updates partition paths, UPDATE accepts a partition assignment (the prepped write takes each record's partition from its values and writes a moved record as a delete where it was read plus an insert), and MERGE INTO flags a clause that assigns a partition column off the looked-up value (`_hoodie.spark.sql.merge.into.moves.records`) so the index merges its records with the ones they match to find the new partition. - Without a record key, MERGE INTO writes the source row of a moved record twice: at the target's location, where the delete clause takes it, and without a location, where an added insert clause writes the updated record to its new partition. Under event-time ordering a record moves only when both the source row's ordering value and the one its update assigns apply the update; it stays when neither does, and the statement fails when they disagree (or the merge mode does not tell). A moved record that more than one source row matches fails the statement with Spark's MERGE_CARDINALITY_VIOLATION wording. UPDATE moves the record through the same prepped write. - Unless the index is global and updates partition paths (or is a custom index), both UPDATE and MERGE INTO refuse a partition assignment off the looked-up value. `TestMergeIntoTable2`, `TestMergeIntoTableWithNonRecordKeyField` and `TestUpdateTable` move records with `UPDATE SET *`, an assigned value and UPDATE on COW and MOR tables with and without a record key, read both partitions, compact the MOR tables, and cover GLOBAL_SIMPLE, the record index with partition path updates, the MERGE INTO and UPDATE refusal under SIMPLE and under the record index with its default `update.partition.path=false`, ordering values that agree and disagree, and two source rows for a moved record. ### Impact UPDATE and MERGE INTO can move a record across partitions: always on a table without a record key, and on a table with one whose global index updates partition paths. On a table with a record key and an index that does not move records, a MERGE INTO clause that assigns a partition column anything but the value its record is looked up under is now refused as UPDATE refuses it, including under RECORD_INDEX with its default `update.partition.path=false` (it wrote the record in place before). On a table without a record key, a MERGE INTO that changes a partition fails when the source row's ordering value and the one its update assigns disagree on whether the update applies, and when more than one source row matches a record it moves. Known gaps: a record moved by MERGE INTO on a table without a record key gets a new generated key; on a MOR table without a record key that has ordering fields, a MERGE INTO that moves a record fails the statement without committing until the delete claus e is applied on such tables (separate fix). ### Risk Level medium. Statements that move nothing take the same path as today; the new paths only run for statements that were refused or wrote the record in place before. The Spark 3 and Spark 4 copies of both commands get the same change. ### 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]
