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;
}
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);
}
}
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;
}
Aggregations