Class BlobCodec
- All Implemented Interfaces:
BatchCodec
Use this codec when producers already write Arrow IPC streams as record values, so one Kafka record holds many rows. Decoding reads each record value as an IPC stream, attaches that record's key, timestamp, partition, offset, and headers to every row through the reserved metadata columns, and concatenates the results; all records in a batch must share one payload schema.
Encoding drops the metadata columns and serializes the payload back into IPC
records: it packs the largest run of consecutive rows that fits under
maxRecordBytes and shares one key, timestamp, and header list, and applies
that envelope to the produced record. A single row larger than the cap throws
ColumnarException instead of producing a record the broker would reject.
Example
var codec = new BlobCodec(allocator); // 900 KiB cap per record
try (var batch = codec.decode("transactions", records)) {
var amounts = (BigIntVector) batch.getVector("amount");
var offsets = (BigIntVector) batch.getVector(BlobCodec.OFFSET_COLUMN);
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe defaultmaxRecordBytes: 900 KiB, safely under a 1 MiB broker limit.static final StringThe reserved column holding each row's encoded Kafka headers,__headers.static final StringThe reserved column holding each row's record key,__key.static final StringThe reserved column holding each row's source offset,__offset.static final StringThe reserved column holding each row's source partition,__partition.static final StringThe reserved column holding each row's record timestamp,__timestamp. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.arrow.vector.VectorSchemaRootdecode(List<ConsumedRecord> records) Decodes Arrow IPC record values into one batch with metadata columns.encode(org.apache.arrow.vector.VectorSchemaRoot batch) Encodes a batch's payload into size-capped Arrow IPC records.static StringpayloadColumn(String name) Returns the in-batch name used when a payload column collides with metadata.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BatchCodec
decode, encode
-
Field Details
-
DEFAULT_MAX_RECORD_BYTES
public static final int DEFAULT_MAX_RECORD_BYTESThe defaultmaxRecordBytes: 900 KiB, safely under a 1 MiB broker limit.- See Also:
-
KEY_COLUMN
The reserved column holding each row's record key,__key.- See Also:
-
TIMESTAMP_COLUMN
The reserved column holding each row's record timestamp,__timestamp.- See Also:
-
PARTITION_COLUMN
The reserved column holding each row's source partition,__partition.- See Also:
-
OFFSET_COLUMN
The reserved column holding each row's source offset,__offset.- See Also:
-
HEADERS_COLUMN
The reserved column holding each row's encoded Kafka headers,__headers.- See Also:
-
-
Constructor Details
-
BlobCodec
public BlobCodec(org.apache.arrow.memory.BufferAllocator allocator) Creates a codec with the 921600-byte record cap.- Parameters:
allocator- the allocator that owns decoded batches
-
BlobCodec
public BlobCodec(org.apache.arrow.memory.BufferAllocator allocator, int maxRecordBytes) Creates a codec with an explicit record size cap.Raise the cap only together with the broker's
max.message.bytes; leave room for headers and framing.- Parameters:
allocator- the allocator that owns decoded batchesmaxRecordBytes- the largest encoded record value the codec may produce- Throws:
IllegalArgumentException- ifmaxRecordBytesis not positive
-
-
Method Details
-
payloadColumn
Returns the in-batch name used when a payload column collides with metadata.A payload column named like a reserved column, for example
__offset, is escaped inside processing batches; sinks restore the original name before encoding. Use this method to address such a column inside operators.- Parameters:
name- the original payload column name- Returns:
- the escaped in-batch name, or
nameitself when it does not collide
-
decode
Decodes Arrow IPC record values into one batch with metadata columns.- Specified by:
decodein interfaceBatchCodec- Parameters:
records- the non-empty records of one topic partition batch- Returns:
- the concatenated batch; the caller must close it
- Throws:
ColumnarException- if the record list is empty, a record is not a readable IPC stream, or the records' payload schemas differ
-
encode
Encodes a batch's payload into size-capped Arrow IPC records.Each produced record's key, timestamp, and headers come from the reserved metadata columns of the rows it carries; a missing or null
__timestampbecomes0and a missing or null__keybecomes a null key.- 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
- Throws:
ColumnarException- if one row alone exceedsmaxRecordBytes
-