You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/05/13 20:37:28 UTC

[GitHub] [beam] iemejia commented on a change in pull request #11641: [BEAM-9931] Support custom Avro DatumReaders in AvroIO

iemejia commented on a change in pull request #11641:
URL: https://github.com/apache/beam/pull/11641#discussion_r424710678



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/io/AvroSource.java
##########
@@ -576,11 +619,16 @@ private static InputStream decodeAsInputStream(byte[] data, String codec) throws
       Schema readerSchema =
           internOrParseSchemaString(
               MoreObjects.firstNonNull(mode.readerSchemaString, writerSchemaString));
-      this.reader =
-          (mode.type == GenericRecord.class)
-              ? new GenericDatumReader<T>(writerSchema, readerSchema)
-              : new ReflectDatumReader<T>(writerSchema, readerSchema);
-      this.decoder = DecoderFactory.get().binaryDecoder(decodeAsInputStream(data, codec), null);
+
+      this.reader = mode.createReader(writerSchema, readerSchema);
+
+      if (codec.equals(DataFileConstants.NULL_CODEC)) {
+        // Avro can read from a byte[] using a more efficient implementation.  If the input is not
+        // compressed, pass the data in directly.
+        this.decoder = DecoderFactory.get().binaryDecoder(data, null);

Review comment:
       Neat!




----------------------------------------------------------------
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:
users@infra.apache.org