[ 
https://issues.apache.org/jira/browse/HIVE-30246?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Denys Kuzmenko updated HIVE-30246:
----------------------------------
    Description: 
*Problem*                                                                       
                                                                                
                                               
  With {{hive.merge.tezfiles=true}}, a DELETE on an Iceberg table gets a merge 
stage (HIVE-28267) for the small files it wrote. The merge task fails in two 
cases:                                               
  # V3 merge-on-read: the DELETE writes deletion vectors in Puffin files, and 
{{IcebergMergeRecordReader}} reads only Avro, ORC and Parquet.                  
                                                   
  # Copy-on-write, any format version: the DELETE writes data files, but the 
merge stage's file sink gets the DELETE operation without the copy-on-write 
flag ({{GenMapRedUtils}}, the {{isCustomDelete}}        
  branch), so it reads the data rows with the delete schema.                    
                                                                                
                                                 
                                                                                
                                                                                
                                                 
  V2 merge-on-read DELETE merges fine. UPDATE and MERGE are not affected: they 
never get a merge stage.                                                        
                                                  
                                                                                
                                                                                
                                                 
  V3 merge-on-read:                                                             
                                                                                
                                                 
  {noformat}                                                                    
                                                                                
                                                 
  TezRuntimeException: Vertex failed, vertexName=File Merge, ...                
                                                                                
                                                 
  Caused by: java.lang.UnsupportedOperationException: Cannot read PUFFIN file: 
file:/.../warehouse/v3_source/data/00000-0-...                                  
                                                  
          at 
org.apache.iceberg.mr.mapreduce.IcebergMergeRecordReader.openGeneric(IcebergMergeRecordReader.java:108)
                                                                                
             
  {noformat}                                                                    
                                                                                
                                                 
                                                                                
                                                                                
                                                 
  Copy-on-write:                                                                
                                                                                
                                                 
  {noformat}                                                                    
                                                                                
                                                 
  TezRuntimeException: Vertex failed, vertexName=File Merge, ...                
                                                                                
                                                 
  Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds 
for length 1                                                                    
                                                    
          at org.apache.iceberg.data.GenericRecord.get(GenericRecord.java:129)  
                                                                                
                                                 
          at 
org.apache.iceberg.mr.hive.serde.objectinspector.IcebergRecordObjectInspector.lambda$getStructFieldsDataAsList$0(IcebergRecordObjectInspector.java:89)
                                              
  {noformat}                         

*Reproducer* (TestIcebergLlapLocalCliDriver)                                    
                                                                                
                                               
  {code:sql}                                                                    
                                                                                
                                                 
  --! qt:dataset:src                                                            
                                                                                
                                                 
  set hive.merge.mapredfiles=true;                                              
                                                                                
                                                 
  set hive.merge.mapfiles=true;                                                 
                                                                                
                                                 
  set hive.merge.tezfiles=true;                                                 
                                                                                
                                                 
  set hive.optimize.sort.dynamic.partition.threshold=-1;                        
                                                                                
                                                 
  set mapred.reduce.tasks=5;                                                    
                                                                                
                                                 
  set hive.blobstore.supported.schemes=hdfs,file;                               
                                                                                
                                                 
                                                                                
                                                                                
                                                 
  -- V3 merge-on-read: tblproperties('format-version'='3')                      
                                                                                
                                                 
  -- copy-on-write:    tblproperties('format-version'='2', 
'write.delete.mode'='copy-on-write')                                            
                                                                      
  create table t(key string) stored by iceberg stored as parquet 
tblproperties('format-version'='3');                                            
                                                                
  insert overwrite table t select key from src;                                 
                                                                                
                                                 
  insert into table t select key from src;                                      
                                                                                
                                                 
  insert into table t select key from src;                                      
                                                                                
                                                 
  insert into table t select key from src;                                      
                                                                                
                                                 
                                                                                
                                                                                
                                                 
  delete from t where key in (select key from src where key < '200');           
                                                                                
                                                 
  {code}                                                                        
                                                                                
                                                 
                                                                                
                                                                                
                                                 
  *Expected*                                                                    
                                                                                
                                                 
  The DELETE succeeds.  

*Proposed fix*                                                                  
                                                                                
                                               
  - V3 merge-on-read: skip DVs ({{ContentFileUtil.isDV}}) when 
{{HiveIcebergOutputCommitter.getOutputFiles}} lists the merge input. A DV 
already holds every deleted position of its data file, so it has nothing
  to gain from the merge. For a V3 DELETE the list is then empty, and 
{{ConditionalResolverMergeFiles}} runs only the move task.                      
                                                           
  - Copy-on-write: give a copy-on-write DELETE no merge stage, as UPDATE and 
MERGE already have none ({{SemanticAnalyzer}} sets {{canBeMerged}} to false for 
them).                                              
 

  was:
*Problem*                                                                       
                                                                                
                                               
  With {{hive.merge.tezfiles=true}}, a DELETE on a format-version 3 Iceberg 
table fails in the File Merge vertex. The merge stage for delete files 
(HIVE-28267) takes every delete file the DELETE wrote as merge
  input. On V3 these are deletion vectors in Puffin files, and 
{{IcebergMergeRecordReader}} reads only Avro, ORC and Parquet.                  
                                                                  
                                                                                
                                                                                
                                                 
  {noformat}                                                                    
                                                                                
                                                 
  TezRuntimeException: Vertex failed, vertexName=File Merge, ...                
                                                                                
                                                 
  Caused by: java.lang.UnsupportedOperationException: Cannot read PUFFIN file: 
file:/.../warehouse/v3_source/data/00000-0-...                                  
                                                  
          at 
org.apache.iceberg.mr.mapreduce.IcebergMergeRecordReader.openGeneric(IcebergMergeRecordReader.java:108)
                                                                                
             
          at 
org.apache.iceberg.mr.mapreduce.IcebergMergeRecordReader.nextTask(IcebergMergeRecordReader.java:59)
                                                                                
                 
          at 
org.apache.iceberg.mr.mapreduce.IcebergMergeRecordReader.initialize(IcebergMergeRecordReader.java:55)
                                                                                
               
          ...                                                                   
                                                                                
                                                 
          at 
org.apache.iceberg.mr.hive.HiveIcebergInputFormat.getRecordReader(HiveIcebergInputFormat.java:232)
                                                                                
                  
          at 
org.apache.hadoop.hive.ql.io.CombineHiveRecordReader.<init>(CombineHiveRecordReader.java:104)
                                                                                
                       
  {noformat}                                                                    
                                                                                
                                                 
                                                                                
                                                                                
                                                 
  Only DELETE is affected: UPDATE and MERGE never get a merge stage.   

  *Reproducer* (TestIcebergLlapLocalCliDriver; iceberg_merge_delete_files.q 
with format-version 3)                                                          
                                                     
  {code:sql}                                                                    
                                                                                
                                                 
  --! qt:dataset:src                                                            
                                                                                
                                                 
  set hive.merge.mapredfiles=true;                                              
                                                                                
                                                 
  set hive.merge.mapfiles=true;                                                 
                                                                                
                                                 
  set hive.merge.tezfiles=true;                                                 
                                                                                
                                                 
  set hive.optimize.sort.dynamic.partition.threshold=-1;                        
                                                                                
                                                 
  set mapred.reduce.tasks=5;                                                    
                                                                                
                                                 
  set hive.blobstore.supported.schemes=hdfs,file;                               
                                                                                
                                                 
                                                                                
                                                                                
                                                 
  create table v3_source(key string) stored by iceberg stored as parquet 
tblproperties('format-version'='3');                                            
                                                        
  insert overwrite table v3_source select key from src;                         
                                                                                
                                                 
  insert into table v3_source select key from src;                              
                                                                                
                                                 
  insert into table v3_source select key from src;                              
                                                                                
                                                 
  insert into table v3_source select key from src;                              
                                                                                
                                                 
                                                                                
                                                                                
                                                 
  delete from v3_source where key in (select key from src where key < '200');   
                                                                                
                                                 
  {code}                                                                        
                                                                                
                                                 
                                                                                
                                                                                
                                                 
  *Expected*                                                                    
                                                                                
                                                 
  The DELETE succeeds. A DV already holds every deleted position of its data 
file, so DVs have nothing to gain from the row-based merge.                     
                                                    
                                                                                
                                                                                
                                                 
  *Proposed fix*                                                                
                                                                                
                                                 
  Skip DVs ({{ContentFileUtil.isDV}}) when 
{{HiveIcebergOutputCommitter.getOutputFiles}} lists the merge input. For a V3 
DELETE the list is then empty, and {{ConditionalResolverMergeFiles}} runs only 
the move 
  task. V2 position-delete files and data files are merged as before.           
        


> Iceberg: DELETE with hive.merge.tezfiles=true fails in the File Merge vertex 
> on V3 and copy-on-write tables 
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: HIVE-30246
>                 URL: https://issues.apache.org/jira/browse/HIVE-30246
>             Project: Hive
>          Issue Type: Bug
>          Components: Iceberg integration
>            Reporter: Denys Kuzmenko
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to