[ 
https://issues.apache.org/jira/browse/BEAM-2303?focusedWorklogId=580831&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-580831
 ]

ASF GitHub Bot logged work on BEAM-2303:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Apr/21 08:29
            Start Date: 12/Apr/21 08:29
    Worklog Time Spent: 10m 
      Work Description: RyanSkraba commented on a change in pull request #14410:
URL: https://github.com/apache/beam/pull/14410#discussion_r611427460



##########
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/coders/AvroCoder.java
##########
@@ -286,10 +289,13 @@ protected AvroCoder(Class<T> type, Schema schema) {
 
           @Override
           public DatumReader<T> initialValue() {
-            return myCoder.getType().equals(GenericRecord.class)
-                ? new GenericDatumReader<>(myCoder.getSchema())
-                : new ReflectDatumReader<>(
-                    myCoder.getSchema(), myCoder.getSchema(), 
myCoder.reflectData.get());
+            if (myCoder.getType().equals(GenericRecord.class)) {
+              return new GenericDatumReader<>(myCoder.getSchema());
+            } else if 
(SpecificRecord.class.isAssignableFrom(myCoder.getType())) {

Review comment:
       This is fun: if the AvroCoder is instantiated as 
`AvroCoder<MySpecificRecord>` it will behave differently than 
`AvroCoder<GenericRecord>`, even though MySpecificRecord is a GenericRecord.  I 
can see this being a gotcha for some developers, but I think it's the right 
thing to do and I don't see an alternative.




-- 
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:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 580831)
    Time Spent: 1h 20m  (was: 1h 10m)

> Add SpecificData to AvroCoder
> -----------------------------
>
>                 Key: BEAM-2303
>                 URL: https://issues.apache.org/jira/browse/BEAM-2303
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-java-core
>    Affects Versions: 2.1.0
>            Reporter: Arvid Heise
>            Assignee: Vitaly Terentyev
>            Priority: P3
>              Labels: Clarified
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> The AvroCoder currently supports GenericData and ReflectData, but not 
> SpecificData.
> It should relatively easy to incorporate it by expanding the logic while 
> constructing the Reader and Writer by also checking if the type implements 
> the SpecificRecord interface. It would greatly speed up (de-)serialization of 
> Avro-generated java classes.
> {code}
>             return myCoder.getType().equals(GenericRecord.class)
>                 ? new GenericDatumReader<T>(myCoder.getSchema())
>                 : new ReflectDatumReader<T>(
>                     myCoder.getSchema(), myCoder.getSchema(), 
> myCoder.reflectData.get());
> {code}
> should be
> {code}
>                         if (myCoder.getType().equals(GenericRecord.class)) {
>                             return new 
> GenericDatumReader<T>(myCoder.getSchema());
>                         }
>                         if 
> (SpecificRecord.class.isAssignableFrom(myCoder.getType())) {
>                             return new 
> SpecificDatumReader<T>(myCoder.getType());
>                         }
>                         return new ReflectDatumReader<T>(
>                                 myCoder.getSchema(), myCoder.getSchema(), 
> myCoder.reflectData.get());
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to