public GenericRecord reencode(GenericRecord r)
        throws AvroSerdeException {
      baos.reset();

      BinaryEncoder be = EncoderFactory.get().directBinaryEncoder(baos, null);
      gdw.setSchema(r.getSchema());
      try {
        gdw.write(r, be);
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

        binaryDecoder = DecoderFactory.defaultFactory().createBinaryDecoder(bais, binaryDecoder);

        return gdr.read(r, binaryDecoder);

      } catch (IOException e) {
        throw new AvroSerdeException("Exception trying to re-encode record to new schema", e);
      }
    }
When encountering a record with an older schema than the one we're trying
to read, it is necessary to re-encode with a reader against the newer schema.
Because Hive doesn't provide a way to pass extra information to the
inputformat, we're unable to provide the newer schema when we have it and it
would be most useful - when the inputformat is reading the file.

This is a slow process, so we try to cache as many of the objects as possible.
serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroDeserializer.java