Class RowCodec<T>
- Type Parameters:
T- the record value type
- All Implemented Interfaces:
BatchCodec
Use this codec when each record holds one value and you want a columnar view of
a topic. Decoding deserializes every value with the supplied Serde,
converts the values into Arrow columns through the RowBridge, and appends
the reserved metadata columns. Encoding reverses it: payload columns become typed
rows, each row becomes one record, and the key, timestamp, and headers are taken
from the __key, __timestamp, and __headers columns. Row
count is preserved in both directions.
The topic passed through decode(String, List) and
encode(String, VectorSchemaRoot) is forwarded to the serde, so
topic-derived schema registry subjects work the same way as in ordinary consumers
and producers.
Example
record Transaction(String user, long amount) {}
var codec = new RowCodec<>(
transactionSerde, new JsonRowBridge<>(Transaction.class), allocator);
try (var batch = codec.decode("transactions", records)) {
// one row per record; columns "user" and "amount" plus metadata
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.arrow.vector.VectorSchemaRootdecode(String topic, List<ConsumedRecord> records) Decodes records, forwarding the topic to the value serde.org.apache.arrow.vector.VectorSchemaRootdecode(List<ConsumedRecord> records) Decodes records with an empty topic name.Encodes a batch into one record per row, forwarding the topic to the serde.encode(org.apache.arrow.vector.VectorSchemaRoot batch) Encodes a batch with an empty topic name.
-
Constructor Details
-
RowCodec
public RowCodec(org.apache.kafka.common.serialization.Serde<T> valueSerde, RowBridge<T> rowBridge, org.apache.arrow.memory.BufferAllocator allocator) Creates a codec from a value serde and a row bridge.- Parameters:
valueSerde- the serde that reads and writes record valuesrowBridge- the bridge between values and Arrow columnsallocator- the allocator that owns decoded batches
-
-
Method Details
-
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, forwarding the topic to the value serde.- 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 record per row, forwarding the topic to the serde.A missing or null
__keybecomes a null record key, and a missing or null__timestampbecomes0.- 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
-