Class AvroRowBridge<T extends org.apache.avro.generic.IndexedRecord>
java.lang.Object
io.krabka.streams.columnar.schema.AvroRowBridge<T>
- Type Parameters:
T- the Avro record type the bridge converts
- All Implemented Interfaces:
RowBridge<T>
public final class AvroRowBridge<T extends org.apache.avro.generic.IndexedRecord>
extends Object
implements RowBridge<T>
Converts Avro records to and from Arrow batches with schema-derived columns.
The Arrow schema comes from AvroArrowSchemas.toArrowSchema(Schema) once, at
construction, so every batch — including an empty one — carries the same columns.
Nested records become Struct columns, arrays List, maps
Map, and the decimal and temporal logical types their native Arrow
counterparts, unlike JsonRowBridge, which
stores nested data as JSON text.
Combine the bridge with an AvroSerde in a
RowCodec to read a registry-framed topic, or
use AvroBatchCodec, which packages exactly that composition.
Example
var bridge = AvroRowBridge.generic(orderSchema);
try (var batch = bridge.rowsToBatch(List.of(order), allocator)) {
List<GenericRecord> back = bridge.batchToRows(batch);
}
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.arrow.vector.types.pojo.SchemaReturns the Arrow schema every batch of this bridge uses.batchToRows(org.apache.arrow.vector.VectorSchemaRoot batch) Converts an Arrow payload batch back into one record per row.static <T extends org.apache.avro.specific.SpecificRecord>
AvroRowBridge<T> forSpecific(Class<T> type) Creates a bridge for a generated Avro class.static AvroRowBridge<org.apache.avro.generic.GenericRecord> generic(org.apache.avro.Schema schema) Creates a bridge for schema-drivenGenericRecordvalues.org.apache.arrow.vector.VectorSchemaRootrowsToBatch(List<T> rows, org.apache.arrow.memory.BufferAllocator allocator) Builds one Arrow batch with one row per record.
-
Method Details
-
generic
public static AvroRowBridge<org.apache.avro.generic.GenericRecord> generic(org.apache.avro.Schema schema) Creates a bridge for schema-drivenGenericRecordvalues.- Parameters:
schema- the record schema every row follows- Returns:
- a generic-record bridge for
schema - Throws:
ColumnarException- if the schema is not a record or uses an unsupported shape
-
forSpecific
public static <T extends org.apache.avro.specific.SpecificRecord> AvroRowBridge<T> forSpecific(Class<T> type) Creates a bridge for a generated Avro class.- Type Parameters:
T- the generated Avro record type- Parameters:
type- the generated class, whose embedded schema drives the columns- Returns:
- a bridge that returns instances of
type - Throws:
ColumnarException- if the embedded schema is not a record or uses an unsupported shape
-
arrowSchema
public org.apache.arrow.vector.types.pojo.Schema arrowSchema()Returns the Arrow schema every batch of this bridge uses.- Returns:
- the Arrow schema derived from the record schema
-
rowsToBatch
public org.apache.arrow.vector.VectorSchemaRoot rowsToBatch(List<T> rows, org.apache.arrow.memory.BufferAllocator allocator) Builds one Arrow batch with one row per record.- Specified by:
rowsToBatchin interfaceRowBridge<T extends org.apache.avro.generic.IndexedRecord>- Parameters:
rows- the records to convert, in record orderallocator- the allocator that owns the batch's buffers- Returns:
- the payload batch; the caller must close it
- Throws:
ColumnarException- if a required field is null or a value cannot be converted
-
batchToRows
Converts an Arrow payload batch back into one record per row.- Specified by:
batchToRowsin interfaceRowBridge<T extends org.apache.avro.generic.IndexedRecord>- Parameters:
batch- the payload batch to convert; the bridge reads it and leaves it open- Returns:
- the records in row order
- Throws:
ColumnarException- if a row cannot be converted back to the record schema
-