Search in sources :

Example 11 with GenericData

use of org.apache.avro.generic.GenericData 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

GenericData (org.apache.avro.generic.GenericData)11 Schema (org.apache.avro.Schema)7 GenericRecord (org.apache.avro.generic.GenericRecord)5 Conversions (org.apache.avro.Conversions)4 File (java.io.File)3 BigDecimal (java.math.BigDecimal)3 DataFileStream (org.apache.avro.file.DataFileStream)3 GenericDatumReader (org.apache.avro.generic.GenericDatumReader)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 BigInteger (java.math.BigInteger)2 Random (java.util.Random)2 GenericRecordBuilder (org.apache.avro.generic.GenericRecordBuilder)2 Path (org.apache.hadoop.fs.Path)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1