shihchengwei-lab commented on PR #20895:
URL: https://github.com/apache/hudi/pull/20895#issuecomment-7136160884

   On `bb69ac7`, `MERGE ... ON false` writes two rows with the same composite 
key `(8, NULL)`. The [duplicate 
check](https://github.com/apache/hudi/blob/bb69ac7fb0fa814678e56ba413eaade0509b153d/hudi-spark-datasource/hudi-spark3-common/src/main/scala/org/apache/spark/sql/hudi/command/MergeIntoHoodieTableCommand.scala#L397-L405)
 filters out both rows before grouping because `part` is `NULL`. The writer 
accepts both and gives them the same record key.
   
   I reproduced this on Spark 3.5.9 with an empty table:
   
   ```sql
   SET hoodie.index.type=SIMPLE;
   
   CREATE TABLE hudi_20895_repro (id INT, part STRING)
   USING hudi TBLPROPERTIES (primaryKey='id,part', type='cow');
   
   MERGE INTO hudi_20895_repro t
   USING (SELECT 8 AS id, CAST(NULL AS STRING) AS part FROM range(2)) s
   ON false WHEN NOT MATCHED THEN INSERT *;
   
   SELECT _hoodie_record_key, COUNT(*) AS copies
   FROM hudi_20895_repro GROUP BY _hoodie_record_key;
   ```
   
   I expected `HoodieDuplicateKeyException` and an empty table. The `MERGE` 
succeeded, and the query returned `id:8,part:__null__` with `copies = 2`.
   
   Could the duplicate check compare the record keys the writer generates so it 
catches this case?


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