bvaradar commented on issue #2131:
URL: https://github.com/apache/hudi/issues/2131#issuecomment-703170642


   > @bvaradar Thanks for the PR.
   > I tried the way you suggested and it is working as desired.
   > Let me know if you see any issue in below code.
   > 
   > ```
   > public class MergeHudiPayload implements 
HoodieRecordPayload<MergeHudiPayload> {
   >     private byte[] recordBytes;
   >     private Schema schema;
   >     private Comparable orderingVal;
   >     
   >     public MergeHudiPayload(GenericRecord genericRecord, Comparable 
orderingVal) {
   >         try {
   >             if (genericRecord!=null) {
   >                 this.recordBytes = 
HoodieAvroUtils.avroToBytes(genericRecord);
   >                 this.schema=genericRecord.getSchema();
   >                 this.orderingVal=orderingVal;
   >             } else {
   >                 this.recordBytes = new byte[0];
   >             }
   >         } catch (IOException io) {
   >             throw new HoodieIOException("Cannot convert record to bytes", 
io);
   >         }
   >     }
   > 
   >    //Constructor called during Compaction
   >     public MergeHudiPayload(Option<GenericRecord> record)  {
   >         this(record.isPresent() ? record.get() : null, (record1) -> 0); // 
natural order
   >     }
   > }
   > ```
   > 
   > Then I use it like this in **preCombine**
   > 
   > ```
   > GenericRecord 
currentRecord=HoodieAvroUtils.bytesToAvro(currentObj.recordBytes,currentObj.schema);
   > GenericRecord 
anotherRecord=HoodieAvroUtils.bytesToAvro(anotherObj.recordBytes,anotherObj.schema);
   > ```
   
   Great. This looks good. Although, Please check if you might want to store 
the schema as a string in the constructors and lazily load. Last I checked Avro 
Schema Object does not implement serializable and you may run into 
Serialization errors 


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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to