From 1d8e7976c6412297dd6b1c5e78993a61388c8c03 Mon Sep 17 00:00:00 2001 From: Javier de la Torre Date: Fri, 6 Nov 2026 18:35:43 +0100 Subject: [PATCH] Avro: read a file without avro.codec as uncompressed The Avro specification makes null the default codec. PyIceberg fell back to the Iceberg table property default (gzip), which is not an Avro codec name, so it raised 'Unsupported codec: gzip' on manifests written without the entry (iceberg-rust writes them so). --- pyiceberg/avro/file.py | 7 +++---- tests/avro/test_file.py | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) 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))