Class ProtobufBatchCodec
- All Implemented Interfaces:
BatchCodec
The codec composes a ProtobufSerde with a ProtobufRowBridge:
each record value is unframed and parsed with the message type's descriptor, then
written as one row whose columns follow the descriptor — nested messages, repeated
fields, maps, and google.protobuf.Timestamp as native Arrow types. The
reserved __key, __timestamp, __partition, __offset,
and __headers columns are appended as for every
RowCodec. The Arrow schema derives from the
local descriptor alone, so a new writer schema mid-stream never changes the
columns; unknown fields are dropped by the descriptor-driven rebuild.
Subjects resolve through the shared SchemaCache: call
registerSubject(String) for every topic the codec reads or writes, then
prewarm the cache before processing.
Example
var codec = ProtobufBatchCodec.of(Order.getDefaultInstance(), 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 the subject through the topic name.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 com.google.protobuf.Message>
ProtobufBatchCodecof(T defaultInstance, SchemaCache cache, org.apache.arrow.memory.BufferAllocator allocator) Creates a codec for one message type.voidregisterSubject(String topic) Interns the message schema for a topic's value subject in the shared cache.
-
Method Details
-
of
public static <T extends com.google.protobuf.Message> ProtobufBatchCodec of(T defaultInstance, SchemaCache cache, org.apache.arrow.memory.BufferAllocator allocator) Creates a codec for one message type.- Type Parameters:
T- the message type- Parameters:
defaultInstance- the default instance of the message type, for exampleOrder.getDefaultInstance()cache- the cache that resolves subjects and writer schemasallocator- the allocator that owns decoded batches- Returns:
- a codec whose columns follow the message descriptor
-
registerSubject
Interns the message 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 message 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 message descriptor
-
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 the subject through the topic name.- 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
-