@Override public Row deserialize(byte[] message) throws IOException { // read record try { inputStream.setBuffer(message); this.record = datumReader.read(record, decoder); } catch (IOException e) { throw new RuntimeException("Failed to deserialize Row.", e); } // convert to row final Object row = convertToRow(schema, record); return (Row) row; }
/** * Creates a Avro deserialization schema for the given record. * * @param recordClazz Avro record class used to deserialize Avro's record to Flink's row */ public AvroRowDeserializationSchema(Class<? extends SpecificRecord> recordClazz) { Preconditions.checkNotNull(recordClazz, "Avro record class must not be null."); this.schema = SpecificData.get().getSchema(recordClazz); this.datumReader = new SpecificDatumReader<>(schema); this.record = (SpecificRecord) SpecificData.newInstance(recordClazz, schema); this.inputStream = new MutableByteArrayInputStream(); this.decoder = DecoderFactory.get().binaryDecoder(inputStream, null); }