Avro: Cache Avro schema conversion in AvroFileHeader.get_schema (#3662) - #3844
Open
hedger9487 wants to merge 1 commit into
Open
Avro: Cache Avro schema conversion in AvroFileHeader.get_schema (#3662)#3844hedger9487 wants to merge 1 commit into
hedger9487 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes Avro manifest/schema handling by caching the Avro-schema-string → Iceberg Schema conversion, avoiding repeated json.loads() + recursive conversion work across many manifest reads during scan planning.
Changes:
- Added an
@lru_cache(maxsize=128)-backed_parse_avro_schema()helper to cache schema parsing/conversion by schema string. - Updated
AvroFileHeader.get_schema()to use the cached helper. - Added a unit test asserting schema conversion results are reused (object identity) across headers with the same embedded schema string.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyiceberg/avro/file.py |
Introduces an LRU-cached schema parsing/conversion helper and routes get_schema() through it. |
tests/avro/test_file.py |
Adds a regression test to ensure schema conversion is cached and reused across calls. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Description
Fixes #3662.
Every manifest file under a partition spec embeds an identical Avro schema string (
avro.schema). Previously,AvroFileHeader.get_schema()inpyiceberg/avro/file.pyperformed a fulljson.loads()and recursiveAvroSchemaConversion().avro_to_iceberg()conversion on every manifest read during scan planning.This PR adds an LRU cache for Avro schema string parsing via
_parse_avro_schema, avoiding redundant conversions across repeated manifest reads during scan planning (e.g. acceleratingscan().plan_files()by ~1.8x on tables with many manifests).Testing
test_get_schema_is_cachedintests/avro/test_file.py.