Class AvroBatchCodec
- All Implemented Interfaces:
BatchCodec
The codec composes an AvroSerde with an AvroRowBridge: each
record value is unframed, resolved from its writer schema onto the fixed reader
schema, and written as one row whose columns follow the reader schema —
structs, lists, maps, decimals, and timestamps as native Arrow types. The reserved
__key, __timestamp, __partition, __offset, and
__headers columns are appended as for every
RowCodec. Because the Arrow schema derives from
the reader schema alone, a new writer schema mid-stream never changes the
columns.
Subjects resolve through the shared SchemaCache: call
registerSubject(String) for every topic the codec reads or writes, then
prewarm the cache before processing. An unknown writer schema ID during decode
starts one background fetch and throws the cache's retriable
SchemaFetchPendingException, exactly as ordinary consumers experience.
Example
var codec = AvroBatchCodec.generic(orderSchema, cache, allocator);
codec.registerSubject("orders");
cache.prewarm().join();
var topology = new ColumnarTopology(allocator);
var source = topology.addSource("orders", List.of("orders"), codec);
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.arrow.vector.types.pojo.SchemaReturns the payload Arrow schema of decoded batches, without the reserved metadata columns.org.apache.arrow.vector.VectorSchemaRootdecode(String topic, List<ConsumedRecord> records) Decodes records, resolving writer schemas through the topic's subject.org.apache.arrow.vector.VectorSchemaRootdecode(List<ConsumedRecord> records) Decodes records with an empty topic name.Encodes a batch into one registry-framed record per row.encode(org.apache.arrow.vector.VectorSchemaRoot batch) Encodes a batch with an empty topic name.static <T extends org.apache.avro.specific.SpecificRecord>
AvroBatchCodecforValue(Class<T> type, SchemaCache cache, org.apache.arrow.memory.BufferAllocator allocator) Creates a codec for a generated Avro class.static AvroBatchCodecgeneric(org.apache.avro.Schema schema, SchemaCache cache, org.apache.arrow.memory.BufferAllocator allocator) Creates a codec for schema-drivenGenericRecordvalues.voidregisterSubject(String topic) Interns the reader schema for a topic's value subject in the shared cache.
-
Method Details
-
generic
public static AvroBatchCodec generic(org.apache.avro.Schema schema, SchemaCache cache, org.apache.arrow.memory.BufferAllocator allocator) Creates a codec for schema-drivenGenericRecordvalues.- Parameters:
schema- the reader schema for every record; must be a record schemacache- the cache that resolves subjects and writer schemasallocator- the allocator that owns decoded batches- Returns:
- a codec whose columns follow
schema
-
forValue
public static <T extends org.apache.avro.specific.SpecificRecord> AvroBatchCodec forValue(Class<T> type, SchemaCache cache, org.apache.arrow.memory.BufferAllocator allocator) Creates a codec for a generated Avro class.- Type Parameters:
T- the generated Avro record type- Parameters:
type- the generated class, whose embedded schema drives the columnscache- the cache that resolves subjects and writer schemasallocator- the allocator that owns decoded batches- Returns:
- a codec whose columns follow the embedded schema of
type
-
registerSubject
Interns the reader schema for a topic's value subject in the shared cache.Call this once per topic before prewarming, exactly as with the underlying serde.
- Parameters:
topic- the topic whose subject resolves the reader schema
-
arrowSchema
public org.apache.arrow.vector.types.pojo.Schema arrowSchema()Returns the payload Arrow schema of decoded batches, without the reserved metadata columns.- Returns:
- the Arrow schema derived from the reader schema
-
decode
Decodes records with an empty topic name.- Specified by:
decodein interfaceBatchCodec- Parameters:
records- the records of one topic partition batch- Returns:
- the decoded batch; the caller must close it
-
decode
Decodes records, resolving writer schemas through the topic's subject.- Specified by:
decodein interfaceBatchCodec- Parameters:
topic- the topic the records were fetched fromrecords- the records of one topic partition batch- Returns:
- the decoded batch, one row per record, with metadata columns appended; the caller must close it
-
encode
Encodes a batch with an empty topic name.- Specified by:
encodein interfaceBatchCodec- Parameters:
batch- the batch to encode; the codec reads it and leaves it open- Returns:
- the encoded records in row order
-
encode
Encodes a batch into one registry-framed record per row.- Specified by:
encodein interfaceBatchCodec- Parameters:
topic- the topic the records will be produced tobatch- the batch to encode; the codec reads it and leaves it open- Returns:
- the encoded records in row order
-