Search in sources :

Example 6 with MutableByteArrayInputStream

use of org.apache.flink.formats.avro.utils.MutableByteArrayInputStream in project flink by apache.

the class AvroDeserializationSchema method checkAvroInitialized.

void checkAvroInitialized() {
    if (datumReader != null) {
        return;
    }
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (SpecificRecord.class.isAssignableFrom(recordClazz)) {
        @SuppressWarnings("unchecked") SpecificData specificData = AvroFactory.getSpecificDataForClass((Class<? extends SpecificData>) recordClazz, cl);
        this.datumReader = new SpecificDatumReader<>(specificData);
        this.reader = AvroFactory.extractAvroSpecificSchema(recordClazz, specificData);
    } else {
        this.reader = new Schema.Parser().parse(schemaString);
        GenericData genericData = new GenericData(cl);
        this.datumReader = new GenericDatumReader<>(null, this.reader, genericData);
    }
    this.inputStream = new MutableByteArrayInputStream();
    this.decoder = DecoderFactory.get().binaryDecoder(inputStream, null);
}
Also used : SpecificData(org.apache.avro.specific.SpecificData) MutableByteArrayInputStream(org.apache.flink.formats.avro.utils.MutableByteArrayInputStream) GenericData(org.apache.avro.generic.GenericData)

Aggregations

MutableByteArrayInputStream (org.apache.flink.formats.avro.utils.MutableByteArrayInputStream)6 Schema (org.apache.avro.Schema)3 Test (org.junit.Test)3 GlueSchemaRegistryDefaultCompression (com.amazonaws.services.schemaregistry.common.GlueSchemaRegistryDefaultCompression)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 GenericData (org.apache.avro.generic.GenericData)2 AWSSchemaRegistryException (com.amazonaws.services.schemaregistry.exception.AWSSchemaRegistryException)1 COMPRESSION (com.amazonaws.services.schemaregistry.utils.AWSSchemaRegistryConstants.COMPRESSION)1 Parser (org.apache.avro.Schema.Parser)1 SchemaParseException (org.apache.avro.SchemaParseException)1 SpecificData (org.apache.avro.specific.SpecificData)1 SpecificDatumWriter (org.apache.avro.specific.SpecificDatumWriter)1 Row (org.apache.flink.types.Row)1