johnclara commented on issue #22574:
URL: https://github.com/apache/beam/issues/22574#issuecomment-1204532745

   There seems to be a workaround by using the GenericRecord to and from row 
methods:
   ```
     private static class MultiUnionSpecificRecordToRowFn implements 
SerializableFunction<MultiUnionSpecificRecord, Row> {
       private final SerializableFunction<GenericRecord, Row> fn;
   
       MultiUnionSpecificRecordToRowFn(SerializableFunction<GenericRecord, Row> 
fn) {
         this.fn = fn;
       }
   
       @Override
       public Row apply(MultiUnionSpecificRecord input) {
         return fn.apply(input);
       }
     }
   
     private static class RowToMultiUnionSpecificRecordFn implements 
SerializableFunction<Row, MultiUnionSpecificRecord> {
       private final SerializableFunction<Row, GenericRecord> fn;
   
       RowToMultiUnionSpecificRecordFn(SerializableFunction<Row, GenericRecord> 
fn) {
         this.fn = fn;
       }
   
       @Override
       public MultiUnionSpecificRecord apply(Row input) {
         GenericRecord genericRecord = fn.apply(input);
         return (MultiUnionSpecificRecord) 
SpecificData.get().deepCopy(MultiUnionSpecificRecord.getClassSchema(), 
genericRecord);
       }
     }
     ```
     ```
         SerializableFunction<MultiUnionSpecificRecord, Row> toRowFunction = 
new MultiUnionSpecificRecordToRowFn(
           
AvroUtils.getGenericRecordToRowFunction(AvroUtils.toBeamSchema(MultiUnionSpecificRecord.getClassSchema()))
       );
       SerializableFunction<Row, MultiUnionSpecificRecord> fromRowFunction = 
new RowToMultiUnionSpecificRecordFn(
           
AvroUtils.getRowToGenericRecordFunction(MultiUnionSpecificRecord.getClassSchema())
       );
   
       PCollection<MultiUnionSpecificRecord> events = p.apply(
           Create.<MultiUnionSpecificRecord>of(record)
               .withSchema(
                   
AvroUtils.toBeamSchema(specificrecord.MultiUnionSpecificRecord.getClassSchema()),
                   
TypeDescriptor.of(specificrecord.MultiUnionSpecificRecord.class),
                   toRowFunction,
                   fromRowFunction
               )
       );
     ```


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