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]