[ 
https://issues.apache.org/jira/browse/BEAM-233?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15269047#comment-15269047
 ] 

Kenneth Knowles edited comment on BEAM-233 at 5/3/16 4:49 PM:
--------------------------------------------------------------

This makes good sense in the event that you have a {{SpecificRecord}} 
implementation in a third party library, where you cannot annotate with 
{{@DefaultCoder(AvroCoder.class)}}. In general, we should make sure that things 
we can do with annotations are also easy to do programmatically, unless it is 
infeasible.

For this, I believe a natural approach would be to add an overload 
{{CoderRegistry#registerCoder(Class<?>, CoderProvider)}} with  the behavior 
that [~eljefe6aa] suggests.


was (Author: kenn):
This makes good sense in the event that you have a {{SpecificRecord}} 
implementation in a third party library, where you cannot annotate with 
{{@DefaultCoder(AvroCoder.class)}}. In general, we should make sure that things 
we can do with annotations are also easy to do programmatically, unless it is 
infeasible.

For this, I believe a natural approach would be to add an overload 
{{CoderRegistry#registerCoder(Class<?>, CoderProvider)}} with  the behavior 
that [~eljefe6aa]] suggests.

> Make Registering Avro Specific Records Easier
> ---------------------------------------------
>
>                 Key: BEAM-233
>                 URL: https://issues.apache.org/jira/browse/BEAM-233
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>            Reporter: Jesse Anderson
>            Assignee: Kenneth Knowles
>
> There should be a helper method to make it easier to register Avro specific 
> record classes. This will be the most common type that needs to be 
> registered. The code would look something like:
> {code:java}
> public class AvroHelper {
>     public static void registerAvro(Pipeline p, Class<? extends 
> SpecificRecordBase> clazz) {
>         p.getCoderRegistry().registerCoder(clazz, new CoderFactory() {
>             @Override
>             public Coder<?> create(List<? extends Coder<?>> componentCoders) {
>                 return AvroCoder.of(clazz);
>             }
>             @Override
>             public List<Object> getInstanceComponents(Object value) {
>                 return null;
>             }
>         });
>     }
> }
> {code}
> With usage:
> {code:java}
>         Pipeline p = Pipeline.create(options);
>         
>         AvroHelper.registerAvro(p, LogEntry.class);
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to