Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pyiceberg/avro/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ def compression_codec(self) -> type[Codec] | None:
"""Get the file's compression codec algorithm from the file's metadata.

In the case of a null codec, we return a None indicating that we
don't need to compress/decompress.
don't need to compress/decompress. A file without the avro.codec
entry is uncompressed: the Avro specification makes "null" the default.
"""
from pyiceberg.table import TableProperties

codec_name = self.meta.get(AVRO_CODEC_KEY, TableProperties.WRITE_AVRO_COMPRESSION_DEFAULT)
codec_name = self.meta.get(AVRO_CODEC_KEY, "null")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if codec_name not in KNOWN_CODECS:
raise ValueError(f"Unsupported codec: {codec_name}")

Expand Down
6 changes: 6 additions & 0 deletions tests/avro/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def get_null_compressor() -> None:
assert header.compression_codec() is None


def test_missing_codec_is_null() -> None:
# the Avro specification: a file without avro.codec is uncompressed (iceberg-rust writes such manifests)
header = AvroFileHeader(bytes(0), {}, bytes(16))
assert header.compression_codec() is None


def test_unknown_codec() -> None:
header = AvroFileHeader(bytes(0), {"avro.codec": "unknown"}, bytes(16))

Expand Down
Loading