yihua opened a new issue, #20837:
URL: https://github.com/apache/hudi/issues/20837
A Spark SQL `MERGE INTO` on a merge-on-read table with a global index
(`GLOBAL_SIMPLE` or `GLOBAL_BLOOM`) writes unreadable rows, or drops its
updates, when the matched records share a small file group with the inserted
ones:
```sql
set hoodie.index.type=GLOBAL_SIMPLE;
create table t (id int, name string, price double, ts long) using hudi
tblproperties (type = 'mor', primaryKey = 'id', orderingFields = 'ts',
'hoodie.record.merge.mode' = 'COMMIT_TIME_ORDERING');
insert into t values (1, 'a1', 10.0, 1000), (2, 'a2', 20.0, 1000), (3, 'a3',
30.0, 1000);
merge into t using (select 1 as id, 'a1m' as name, 11.0D as price, 2000L as
ts
union all select 2, 'a2m', 21.0D, 2000L union all select 4, 'a4', 40.0D,
2000L) s
on t.id = s.id when matched then update set * when not matched then insert *;
select * from t;
-- (1,,5.149096449E-314,,0) (1,,2.01137845E-316,,0) (3,a3,30.0,1000)
(4,a4,40.0,2000)
```
With `EVENT_TIME_ORDERING` the statement succeeds and leaves ids 1 and 2
unchanged. Compaction keeps the corrupt rows. The same statement is correct
with `SIMPLE` or a bucket index on MOR and with `GLOBAL_SIMPLE` on COW. On COW
and MOR alike, a MERGE that moves a record to another partition with a global
index writes the moved row unreadable when that partition has a small file
group (`(1,,5.149096449E-314,0,p2)`).
On a merge-on-read table, and for a partition move on either table type, a
global index merges each matched record with its current version while tagging
it (`HoodieIndexUtils#mergeForPartitionUpdatesAndDeletionsIfNeeded`). For
`ExpressionPayload` the result is a final row in the table schema with the
table's payload class. When the target file group also takes inserts,
`BaseSparkDeltaCommitActionExecutor#handleUpdate` sends its records to the
merge handle rather than the append handle (COW inserts into a small file
always use it). There `StreamingFileGroupRecordBufferLoader#getRecordSchema`
decodes every incoming record with the `ExpressionPayload` record schema
(`hoodie.payload.record.schema`), so the merged rows are decoded with the wrong
schema, and the `ExpressionPayload` merger then evaluates the MERGE clauses
again on them.
Proposal: in the merge handle, buffer the records that the index already
merged in the table schema, and keep them as final rows instead of evaluating
the MERGE clauses on them.
--
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]