yihua opened a new pull request, #20857:
URL: https://github.com/apache/hudi/pull/20857

   ### Describe the issue this Pull Request addresses
   
   closes #20856
   
   On a merge-on-read table, a Spark SQL `MERGE INTO` whose `WHEN MATCHED` 
condition refers to a target column is evaluated against the source row only. 
The append handle swallows the resulting `ArrayIndexOutOfBoundsException` 
(`hoodie.write.ignore.failed`), so the statement reports success and leaves the 
matched rows unchanged. A target column in an assigned value is refused on 
merge-on-read tables, although copy-on-write tables support it.
   
   ### Summary and Changelog
   
   On a merge-on-read table with a record key, matched clauses that refer to 
target columns are now evaluated against the target row; a table without a 
record key refuses such a condition at analysis.
   
   - `MergeIntoHoodieTableCommand` sets the internal flag 
`_hoodie.spark.sql.merge.into.reads.target` when a matched condition or 
assigned value refers to a target column, and then binds the statement as for 
copy-on-write (no partial update schema, left-out columns from the target row, 
no refusal of target columns in assigned values).
   - With the flag, the MOR upsert merges the located records with the rows 
they match right after the index lookup 
(`HoodieIndexUtils#mergeLocatedExpressionPayloadRecords`), reading the latest 
merged file slices of the located file groups, and appends full rows or deletes 
to the log. A located record with no live row at its location (a key deleted in 
a log file, or a new key in a bucket of the bucket index) takes the not-matched 
clauses there. Small-file packing is off for such statements.
   - `ExistingRecordMerger` is factored out of the merged lookup of global 
indexes so both paths read and merge existing records the same way.
   - New tests in `TestMergeIntoTable2` cover update, update plus delete with 
insert, and assigned values on partitioned and non-partitioned MOR tables with 
SIMPLE, GLOBAL_SIMPLE, RECORD_INDEX and BUCKET indexes, before and after 
compaction, a merge into a key deleted in the log, and the refusal on a keyless 
MOR table.
   
   ### Impact
   
   MERGE INTO on merge-on-read tables applies matched clauses that reference 
target columns instead of silently skipping them, and accepts target columns in 
assigned values. Statements that do not reference target columns are written as 
before. A statement with only a conditional WHEN MATCHED DELETE on a table 
without an ordering field still runs as an insert and is not covered here.
   
   ### Risk Level
   
   medium. Flagged statements read the latest file slices of every matched file 
group once, as copy-on-write merges already do; other statements are unchanged.
   
   ### 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]

Reply via email to