public static GenericData.Record project(final SpecificRecord object, final
Schema projectionSchema)
throws IOException {
ByteArrayBuilder bab = new ByteArrayBuilder(128);
DatumWriter<T> writer = new SpecificDatumWriter<>((Class<T>)
object.getClass());
Encoder encoder = EncoderFactory.get().binaryEncoder(bab, null);
writer.write(object, encoder);
encoder.flush();
DatumReader<Object> reader = new GenericDatumReader<>(object.getSchema(),
projectionSchema);
DecoderFactory decoderFactory = DecoderFactory.get();
Decoder decoder = decoderFactory.binaryDecoder(new
ByteArrayInputStream(bab.getBuffer(), 0, bab.size()), null);
return (GenericData.Record) reader.read(null, decoder);
}
Is there a better way to obtain a projection of a SpecificRecord? The
se/derialization to byte[] seems unnecessary...
Let me know,
Thank you
--Z
This message contains confidential information and is intended only for the
individual named. If you are not the named addressee, you should not
disseminate, distribute, alter or copy this e-mail. Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and delete
this e-mail from your system. E-mail transmissions cannot be guaranteed to be
secure or without error as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The sender,
therefore, does not accept liability for any errors or omissions in the
contents of this message which arise during or as a result of e-mail
transmission. If verification is required, please request a hard-copy version.
This message is provided for information purposes and should not be construed
as a solicitation or offer to buy or sell any securities or related financial
instruments in any jurisdiction. Securities are offered in the U.S. through
PIMCO Investments LLC, distributor and a company of PIMCO LLC.