diff --git a/pyiceberg/avro/file.py b/pyiceberg/avro/file.py index 3184e3950a..4b23c30ac0 100644 --- a/pyiceberg/avro/file.py +++ b/pyiceberg/avro/file.py @@ -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") if codec_name not in KNOWN_CODECS: raise ValueError(f"Unsupported codec: {codec_name}") diff --git a/tests/avro/test_file.py b/tests/avro/test_file.py index 6cc190c33b..12d1af2ce2 100644 --- a/tests/avro/test_file.py +++ b/tests/avro/test_file.py @@ -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))