Repository navigation
Conversation
PEP 784 makes compression.zstd optional, so on Python 3.14+ builds without libzstd the Avro codec import failed at module load and broke reading any manifest, and Puffin imports failed the same way when the zstandard package was missing. Move the backend selection into a shared pyiceberg.utils.zstd module that tries the stdlib module first, then the zstandard package, and only raises ImportError on use when neither is available. Refs apache#4495
3 tasks
mypy with no_implicit_reexport rejects importing ZStandardCodec through the pyiceberg.avro.codecs package, which does not explicitly re-export it. Import it from pyiceberg.avro.codecs.zstandard_codec instead.
On Python 3.14 the stdlib compression.zstd backend reports a truncated frame as 'Compressed data ended before the end-of-stream marker was reached', which the existing match terms do not cover, so the truncated frame and concatenated frames tests failed on 3.14 only. Widen both matches with end-of-stream.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Refs #4495 (first follow-up item only; the cp315 wheel smoke test and the Python 3.15 CI items are not covered here).
PEP 784 makes
compression.zstdoptional: it is only built when libzstd is available. On a Python 3.14+ build without it, the import inpyiceberg/avro/codecs/zstandard_codec.pyraises at module load, and becausepyiceberg/avro/codecs/__init__.pyimportsZStandardCodeceagerly, reading any manifest breaks.pyiceberg/table/puffin.pyhas the same flaw when thezstandardpackage is missing. With thepython_version < '3.14'marker on thezstandarddependency, users also cannot recover through the dependency itself.This adds a shared
pyiceberg/utils/zstd.pymodule that triescompression.zstdfirst, then thezstandardpackage, and only raisesImportErroron use when neither is available. The Avro codec and Puffin both go through it. Thezstandardbackend decompresses frame by frame and checks each frame is complete, so truncated or concatenated frames behave as before. The install hint now points atpip install zstandard, since there is nopyiceberg[zstandard]extra.Are these changes tested?
Yes. New tests in
tests/table/test_puffin.pycover the roundtrip, raising only on use when no backend is available, a fresh interpreter import with bothzstandardandcompression.zstdblocked (imports ofpyiceberg.manifest, the codec and Puffin succeed), and truncated and concatenated frames.tests/table/test_puffin.py,tests/avro/andtests/utils/test_manifest.py: 243 passed, run twice with the same result. The new no-backend test fails on base.Are there any user-facing changes?
No API changes. Manifest and Puffin reads no longer fail at import time on Python builds without stdlib
compression.zstd; zstd-compressed data raisesImportErroronly when it is actually read and no backend is installed.