Class AvroRowReader

java.lang.Object
dev.hardwood.avro.AvroRowReader
All Implemented Interfaces:
Closeable, AutoCloseable

public class AvroRowReader extends Object implements Closeable

Reads Parquet rows as Avro GenericRecord instances.

Wraps a Hardwood RowReader and materializes each row into a GenericRecord using the converted Avro schema. Values are stored in Avro's raw representation (e.g. timestamps as Long, bytes-backed decimals as ByteBuffer, fixed-typed columns as GenericData.Fixed). parquet-java's AvroReadSupport uses the same representations, except that it reads decimals over INT32 and INT64 as Integer and Long, and reads an INT96 as a fixed only when parquet.avro.readInt96AsFixed is set.

try (AvroRowReader reader = AvroReaders.rowReader(fileReader)) {
    while (reader.hasNext()) {
        GenericRecord record = reader.next();
        long id = (Long) record.get("id");
    }
}
  • Method Details

    • hasNext

      public boolean hasNext() throws IOException
      Check if there are more rows to read.
      Returns:
      true if there are more rows
      Throws:
      IOException
    • next

      public org.apache.avro.generic.GenericRecord next() throws IOException
      Advance to the next row and return it as a GenericRecord.
      Returns:
      the current row as a GenericRecord
      Throws:
      IOException
    • getSchema

      public org.apache.avro.Schema getSchema()
      Returns the Avro schema used for materialization.
      Returns:
      the Avro record schema
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException