Indian-boult opened a new issue, #20861:
URL: https://github.com/apache/hudi/issues/20861

   ### Bug Description
   
   **What happened:**
   
   On a merge-on-read table with event time ordering, a key deleted with the 
`delete` operation comes back with its old values when it is upserted again 
with a lower ordering value than the deleted row. The new write is lost, and 
compaction then makes the old row permanent. A copy-on-write table with the 
same writes returns the new row.
   
   **What you expected:**
   
   The upsert after the delete writes a new row, as on COW. The `delete` 
operation writes a delete with no ordering value, which removes the row 
whatever its ordering value, so the next upsert of that key should not be 
compared with the deleted row.
   
   **Steps to reproduce:**
   1. Create a MOR table with record key `id`, 
`hoodie.table.ordering.fields=version` and 
`hoodie.write.record.merge.mode=EVENT_TIME_ORDERING`.
   2. Insert `(1, a, 100)` and `(2, b, 100)`.
   3. Write `(1, a, 100)` with `hoodie.datasource.write.operation=delete`. A 
snapshot read returns only key 2.
   4. Upsert `(1, c, 90)`.
   5. A snapshot read returns `(1, a, 100)` and `(2, b, 100)`. On COW it 
returns `(1, c, 90)` and `(2, b, 100)`.
   
   **Cause:**
   
   `EventTimeRecordMerger.deltaMerge` in `BufferedRecordMergerFactory` keeps 
the upsert over the earlier delete in the log files, since the delete has no 
ordering value, and drops the delete. `finalMerge` then compares the upsert 
with the base file record by ordering value alone, so the deleted base record 
with version 100 wins over the upsert with version 90. 
`EventTimePartialRecordMerger` has the same gap.
   
   **Fix:**
   
   I have a change that marks a record kept over such a delete during the log 
merge, keeps the mark through later delta merges and the spillable map, and 
makes `finalMerge` keep a marked record over the base file record. A new test 
in `TestKeyBasedFileGroupRecordBuffer` and a COW and MOR test in 
`TestMORDataSource` fail on master and pass with it. `TestMORDataSource`, 
`TestBufferedRecordMerger`, `TestPositionBasedFileGroupRecordBuffer`, 
`TestMergeModeEventTimeOrdering`, `TestDeleteFromTable` and `TestDeleteTable` 
pass. I can open a PR if this approach works for you.
   
   ### Environment
   
   **Hudi version:** master at e4c229dab
   **Query engine:** Spark 3.5
   **Relevant configs:** `hoodie.write.record.merge.mode=EVENT_TIME_ORDERING`, 
`hoodie.table.ordering.fields=version`, default SIMPLE index
   
   ### Logs and Stack Trace
   
   TestMORDataSource#testUpsertAfterDeleteWithLowerOrderingValue on master, MOR 
with AVRO and SPARK records:
   
   expected: <List((1,c,90), (2,b,100))> but was: <WrappedArray((1,a,100), 
(2,b,100))>
   
   
TestKeyBasedFileGroupRecordBuffer#readWithEventTimeOrderingAndUpsertAfterCommitTimeDelete
 on master, key 2 comes back with the deleted base values:
   
   expected: <[{"record_key": "1", "counter": 1, "ts": 1}, {"record_key": "2", 
"counter": 1, "ts": 0}, {"record_key": "3", "counter": 1, "ts": 1}]> but was: 
<[{"record_key": "1", "counter": 1, "ts": 1}, {"record_key": "2", "counter": 1, 
"ts": 1}, {"record_key": "3", "counter": 1, "ts": 1}]>


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