Denys Kuzmenko created HIVE-30126:
-------------------------------------

             Summary: Iceberg: copy-on-write MERGE skips the cardinality check, 
so a target row matched by several source rows is written several times
                 Key: HIVE-30126
                 URL: https://issues.apache.org/jira/browse/HIVE-30126
             Project: Hive
          Issue Type: Bug
            Reporter: Denys Kuzmenko


MergeRewriter adds a cardinality check when hive.merge.cardinality.check=true, 
the default. The query fails if more than one source row matches the same 
target row in a WHEN MATCHED UPDATE or  DELETE, as SQL:2011 (ISO/IEC 9075-2, 
14.2) requires. Merge-on-read MERGE (SplitMergeRewriter) inherits the check. 
CopyOnWriteMergeRewriter.rewrite does not add it:

 // TODO: handleCardinalityViolation;                                           
                                                                                
                                       
So a copy-on-write MERGE with duplicate source keys succeeds and writes one 
updated copy of the target row per matching source row.   

*Repro:   *               
{code}                                                                          
                                                                                
                    
  create table tgt (id int, v int) stored by iceberg                            
                                                                                
                                        
    tblproperties ('format-version'='2', 'write.merge.mode'='copy-on-write');   
                                                                                
                                        
  insert into tgt values (1, 10), (2, 20);                                      
                                                                                
                                        
  create table src (id int, v int);                                             
                                                                                
                                        
  insert into src values (1, 100), (1, 200);                                    
                                                                                
                                        
                                                                                
                                                                                
                                        
  merge into tgt t using src s on t.id = s.id                                   
                                                                                
                                        
  when matched then update set v = s.v;                                         
                                                                                
                                        
                                                                                
                                                                                
                                        
  select * from tgt order by id, v;                                             
                                                                                
                                        
  -- merge-on-read: fails with a cardinality violation                          
                                                                                
                                        
  -- copy-on-write: succeeds, returns (1,100), (1,200), (2,20); the target row 
is duplicated   
{code}                                                                 




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to