yihua opened a new issue, #20818:
URL: https://github.com/apache/hudi/issues/20818

   When a Spark SQL `MERGE INTO` has no `WHEN MATCHED ... THEN UPDATE` clause 
and the table has no ordering field, `MergeIntoHoodieTableCommand` writes the 
source with the `insert` operation. An insert never finds the target record, so 
every source row takes the not-matched clauses:
   
   - `WHEN MATCHED ... THEN DELETE` deletes nothing.
   - On a table with a record key, `WHEN NOT MATCHED THEN INSERT` inserts a 
source row whose key the table already holds, which leaves two records with one 
key.
   - On a table without a record key, a source row that matches a target row is 
inserted as a new row.
   
   For example, on a table with `primaryKey = 'id'` and no ordering field,
   
   ```sql
   merge into t using (select 1 as id) s on t.id = s.id
   when matched then delete
   ```
   
   leaves the row with `id = 1` in place.
   
   I'd propose writing such a statement as an upsert whenever the table has a 
record key, or when the statement has a matched clause, as the command already 
does for a statement with an update clause.
   


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