yihua opened a new issue, #20819: URL: https://github.com/apache/hudi/issues/20819
A Spark SQL `MERGE INTO` with only `WHEN NOT MATCHED ... THEN INSERT` clauses on a table with a record key can lose an insert when two source rows share a key and only one of them passes the insert condition. When the statement is written as an upsert (for example on a table with an ordering field), the write combines the source rows by key before `ExpressionPayload` evaluates the clause conditions, so the row that fails the condition can take the place of the one that passes it, and nothing is inserted for that key. ```sql -- table with primaryKey = 'id', preCombineField = 'ts' merge into t using (select 4 as id, 10.4 as price, 1004 as ts union all select 4, 1.4, 1005) s on t.id = s.id when not matched and s.price > 5 then insert * ``` inserts nothing for `id = 4`, where the row with `price = 10.4` is expected. A source row that no not-matched clause accepts writes nothing, so I'd propose filtering the source by the insert conditions before the write when the statement has no matched clause and every insert condition is deterministic. -- 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]
