Search in sources :

Example 1 with GenericContainer

use of org.apache.avro.generic.GenericContainer in project storm by apache.

the class AbstractAvroSerializer method read.

@Override
public GenericContainer read(Kryo kryo, Input input, Class<GenericContainer> aClass) {
    Schema theSchema = this.getSchema(input.readString());
    GenericDatumReader<GenericContainer> reader = new GenericDatumReader<>(theSchema);
    Decoder decoder = DecoderFactory.get().directBinaryDecoder(input, null);
    GenericContainer foo;
    try {
        foo = reader.read(null, decoder);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return foo;
}
Also used : GenericDatumReader(org.apache.avro.generic.GenericDatumReader) Schema(org.apache.avro.Schema) IOException(java.io.IOException) GenericContainer(org.apache.avro.generic.GenericContainer) Decoder(org.apache.avro.io.Decoder)

Example 2 with GenericContainer

use of org.apache.avro.generic.GenericContainer in project storm by apache.

the class AbstractAvroSerializer method write.

@Override
public void write(Kryo kryo, Output output, GenericContainer record) {
    String fingerPrint = this.getFingerprint(record.getSchema());
    output.writeString(fingerPrint);
    GenericDatumWriter<GenericContainer> writer = new GenericDatumWriter<>(record.getSchema());
    BinaryEncoder encoder = EncoderFactory.get().directBinaryEncoder(output, null);
    try {
        writer.write(record, encoder);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : BinaryEncoder(org.apache.avro.io.BinaryEncoder) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) IOException(java.io.IOException) GenericContainer(org.apache.avro.generic.GenericContainer)

Example 3 with GenericContainer

use of org.apache.avro.generic.GenericContainer in project drill by apache.

the class AvroRecordReader method next.

@Override
public int next() {
    final Stopwatch watch = Stopwatch.createStarted();
    if (reader == null) {
        throw new IllegalStateException("Avro reader is not open.");
    }
    if (!reader.hasNext()) {
        return 0;
    }
    int recordCount = 0;
    writer.allocate();
    writer.reset();
    try {
        for (GenericContainer container = null; recordCount < DEFAULT_BATCH_SIZE && reader.hasNext() && !reader.pastSync(end); recordCount++) {
            writer.setPosition(recordCount);
            container = reader.next(container);
            processRecord(container, container.getSchema());
        }
        writer.setValueCount(recordCount);
    } catch (IOException e) {
        throw new DrillRuntimeException(e);
    }
    logger.debug("Read {} records in {} ms", recordCount, watch.elapsed(TimeUnit.MILLISECONDS));
    return recordCount;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) GenericContainer(org.apache.avro.generic.GenericContainer) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Aggregations

IOException (java.io.IOException)3 GenericContainer (org.apache.avro.generic.GenericContainer)3 Stopwatch (com.google.common.base.Stopwatch)1 Schema (org.apache.avro.Schema)1 GenericDatumReader (org.apache.avro.generic.GenericDatumReader)1 GenericDatumWriter (org.apache.avro.generic.GenericDatumWriter)1 BinaryEncoder (org.apache.avro.io.BinaryEncoder)1 Decoder (org.apache.avro.io.Decoder)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1