You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by "kulkarni.swarnim@gmail.com" <ku...@gmail.com> on 2013/10/30 20:07:34 UTC

GenericDatumReader and datum reuse

Hello,

While going thorough the API for GenericDatumReader, I came across this
read[1] method and it wasn't immediately clear to me as to what the "reuse"
of the datum really means.

So for instance if I have an evolving schema, should this datum be created
from the readerSchema or the writerSchema. So something like:

record = new GenericData.Record(readerSchema); // created with readerSchema

GenericDatumReader<GenericRecord> gdr =
newGenericDatumReader<GenericRecord>(writerSchema, readerSchema);

record = gdr.read(record, binaryDecoder);

Or is it better to simply leave it off as null?

record = gdr.read(null, binaryDecoder);


Thanks,

[1]
http://avro.apache.org/docs/1.7.4/api/java/org/apache/avro/generic/GenericDatumReader.html#read(D,
org.apache.avro.io.Decoder)

Re: GenericDatumReader and datum reuse

Posted by Doug Cutting <cu...@apache.org>.
A simple approach to reuse is to pass the value previously returned from read():

GenericRecord record = null;
while (...) {
  record = reader.read(record, decoder);
  ... code that does not retain a pointer to record ...
}

Doug

On Wed, Oct 30, 2013 at 3:07 PM, kulkarni.swarnim@gmail.com
<ku...@gmail.com> wrote:
> Hello,
>
> While going thorough the API for GenericDatumReader, I came across this
> read[1] method and it wasn't immediately clear to me as to what the "reuse"
> of the datum really means.
>
> So for instance if I have an evolving schema, should this datum be created
> from the readerSchema or the writerSchema. So something like:
>
> record = new GenericData.Record(readerSchema); // created with readerSchema
>
> GenericDatumReader<GenericRecord> gdr = new
> GenericDatumReader<GenericRecord>(writerSchema, readerSchema);
>
> record = gdr.read(record, binaryDecoder);
>
> Or is it better to simply leave it off as null?
>
> record = gdr.read(null, binaryDecoder);
>
>
> Thanks,
>
>
> [1]
> http://avro.apache.org/docs/1.7.4/api/java/org/apache/avro/generic/GenericDatumReader.html#read(D,
> org.apache.avro.io.Decoder)