Class GzipBatchCodec
java.lang.Object
io.krabka.streams.columnar.GzipBatchCodec
- All Implemented Interfaces:
BatchCodec
Adds per-record GZIP compression to any batch codec.
Encoding compresses each produced record's value after the delegate has encoded
it; decoding decompresses each fetched record's value before the delegate sees it.
Keys, timestamps, and headers pass through unchanged. Decompression is capped to
guard against decompression bombs: a record that inflates past
maxUncompressedBytes throws ColumnarException.
Example
var codec = new GzipBatchCodec(new BlobCodec(allocator));
topology.addSource("source", List.of("compressed-transactions"), codec);
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default decompression ceiling: 16 MiB per record. -
Constructor Summary
ConstructorsConstructorDescriptionGzipBatchCodec(BatchCodec delegate) Wraps a codec with the 16777216-byte ceiling.GzipBatchCodec(BatchCodec delegate, int maxUncompressedBytes) Wraps a codec with an explicit decompression ceiling. -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.arrow.vector.VectorSchemaRootdecode(String topic, List<ConsumedRecord> records) Decompresses record values, then delegates decoding.org.apache.arrow.vector.VectorSchemaRootdecode(List<ConsumedRecord> records) Decompresses record values, then decodes them with an empty topic name.Delegates encoding, then compresses each record value.encode(org.apache.arrow.vector.VectorSchemaRoot batch) Encodes with an empty topic name, then compresses each record value.
-
Field Details
-
DEFAULT_MAX_UNCOMPRESSED_BYTES
public static final int DEFAULT_MAX_UNCOMPRESSED_BYTESThe default decompression ceiling: 16 MiB per record.- See Also:
-
-
Constructor Details
-
GzipBatchCodec
Wraps a codec with the 16777216-byte ceiling.- Parameters:
delegate- the codec that handles the uncompressed record values
-
GzipBatchCodec
Wraps a codec with an explicit decompression ceiling.- Parameters:
delegate- the codec that handles the uncompressed record valuesmaxUncompressedBytes- the largest value a record may decompress to- Throws:
IllegalArgumentException- if the ceiling is not positive or isInteger.MAX_VALUE
-
-
Method Details
-
decode
Decompresses record values, then decodes them with an empty topic name.- Specified by:
decodein interfaceBatchCodec- Parameters:
records- the records of one topic partition batch- Returns:
- the delegate's decoded batch; the caller must close it
-
decode
Decompresses record values, then delegates decoding.- Specified by:
decodein interfaceBatchCodec- Parameters:
topic- the topic the records were fetched fromrecords- the records of one topic partition batch- Returns:
- the delegate's decoded batch; the caller must close it
- Throws:
ColumnarException- if a value is not valid GZIP or inflates past the ceiling
-
encode
Encodes with an empty topic name, then compresses each record value.- Specified by:
encodein interfaceBatchCodec- Parameters:
batch- the batch to encode; the codec reads it and leaves it open- Returns:
- the compressed records in the delegate's order
-
encode
Delegates encoding, then compresses each record value.- 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 compressed records in the delegate's order
-