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

   Spark SQL MERGE INTO on a Hudi table with a record key accepts an ON 
condition that leaves out a record key column, unless 
`hoodie.spark.sql.optimized.writes.enable` is explicitly set to `true` in the 
session. The write then takes the record key from the source column of the same 
name, so the statement matches different rows than its ON condition says. For a 
table with record key `id` holding `(1, 'a1')` and `(2, 'a2')`:
   
   ```sql
   MERGE INTO t USING (SELECT 2 AS id, 'a1' AS name, 11.0 AS price, 1001L AS 
ts) s
   ON t.name = s.name
   WHEN MATCHED THEN UPDATE SET price = s.price, ts = s.ts
   ```
   
   updates row 2 instead of row 1. With a composite record key `(id, name)` and 
`ON t.id = s.id`, a source row that matches on `id` but carries a different 
`name` is inserted as a new record instead of updating the matched one.
   
   `MergeIntoHoodieTableCommand#recordKeyAttributeToConditionExpression` 
already rejects such a statement ("Hudi tables with record key are required to 
match on all record key columns"), but only when 
`getConfString(SPARK_SQL_OPTIMIZED_WRITES.key(), "false") == "true"`. The 
config defaults to `true`, so the check is skipped by default, and skipped when 
it is set to `false`.
   
   Proposal: always run the check for tables with a record key.
   


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