@@ -59,7 +59,7 @@ public class HoodieCreateHandle<T extends HoodieRecordPayload, I, K, O> extends
5959 protected long recordsDeleted = 0 ;
6060 private Map <String , HoodieRecord <T >> recordMap ;
6161 private boolean useWriterSchema = false ;
62- private boolean preserveHoodieMetadata = false ;
62+ private final boolean preserveMetadata ;
6363
6464 public HoodieCreateHandle (HoodieWriteConfig config , String instantTime , HoodieTable <T , I , K , O > hoodieTable ,
6565 String partitionPath , String fileId , TaskContextSupplier taskContextSupplier ) {
@@ -69,9 +69,9 @@ public HoodieCreateHandle(HoodieWriteConfig config, String instantTime, HoodieTa
6969
7070 public HoodieCreateHandle (HoodieWriteConfig config , String instantTime , HoodieTable <T , I , K , O > hoodieTable ,
7171 String partitionPath , String fileId , TaskContextSupplier taskContextSupplier ,
72- boolean preserveHoodieMetadata ) {
72+ boolean preserveMetadata ) {
7373 this (config , instantTime , hoodieTable , partitionPath , fileId , Option .empty (),
74- taskContextSupplier , preserveHoodieMetadata );
74+ taskContextSupplier , preserveMetadata );
7575 }
7676
7777 public HoodieCreateHandle (HoodieWriteConfig config , String instantTime , HoodieTable <T , I , K , O > hoodieTable ,
@@ -82,10 +82,10 @@ public HoodieCreateHandle(HoodieWriteConfig config, String instantTime, HoodieTa
8282
8383 public HoodieCreateHandle (HoodieWriteConfig config , String instantTime , HoodieTable <T , I , K , O > hoodieTable ,
8484 String partitionPath , String fileId , Option <Schema > overriddenSchema ,
85- TaskContextSupplier taskContextSupplier , boolean preserveHoodieMetadata ) {
85+ TaskContextSupplier taskContextSupplier , boolean preserveMetadata ) {
8686 super (config , instantTime , partitionPath , fileId , hoodieTable , overriddenSchema ,
8787 taskContextSupplier );
88- this .preserveHoodieMetadata = preserveHoodieMetadata ;
88+ this .preserveMetadata = preserveMetadata ;
8989 writeStatus .setFileId (fileId );
9090 writeStatus .setPartitionPath (partitionPath );
9191 writeStatus .setStat (new HoodieWriteStat ());
@@ -111,7 +111,7 @@ public HoodieCreateHandle(HoodieWriteConfig config, String instantTime, HoodieTa
111111 public HoodieCreateHandle (HoodieWriteConfig config , String instantTime , HoodieTable <T , I , K , O > hoodieTable ,
112112 String partitionPath , String fileId , Map <String , HoodieRecord <T >> recordMap ,
113113 TaskContextSupplier taskContextSupplier ) {
114- this (config , instantTime , hoodieTable , partitionPath , fileId , taskContextSupplier );
114+ this (config , instantTime , hoodieTable , partitionPath , fileId , taskContextSupplier , config . isPreserveHoodieCommitMetadataForCompaction () );
115115 this .recordMap = recordMap ;
116116 this .useWriterSchema = true ;
117117 }
@@ -137,13 +137,11 @@ public void write(HoodieRecord record, Option<IndexedRecord> avroRecord) {
137137 return ;
138138 }
139139 // Convert GenericRecord to GenericRecord with hoodie commit metadata in schema
140- IndexedRecord recordWithMetadataInSchema = rewriteRecord ((GenericRecord ) avroRecord .get ());
141- if (preserveHoodieMetadata ) {
142- // do not preserve FILENAME_METADATA_FIELD
143- recordWithMetadataInSchema .put (HoodieRecord .HOODIE_META_COLUMNS_NAME_TO_POS .get (HoodieRecord .FILENAME_METADATA_FIELD ), path .getName ());
144- fileWriter .writeAvro (record .getRecordKey (), recordWithMetadataInSchema );
140+ if (preserveMetadata ) {
141+ fileWriter .writeAvro (record .getRecordKey (),
142+ rewriteRecordWithMetadata ((GenericRecord ) avroRecord .get (), path .getName ()));
145143 } else {
146- fileWriter .writeAvroWithMetadata (recordWithMetadataInSchema , record );
144+ fileWriter .writeAvroWithMetadata (rewriteRecord (( GenericRecord ) avroRecord . get ()) , record );
147145 }
148146 // update the new location of record, so we know where to find it next
149147 record .unseal ();
0 commit comments