chore: allow optional whitespace around parameters similar to other language implementations#3530
Open
sungwy wants to merge 1 commit into
Open
chore: allow optional whitespace around parameters similar to other language implementations#3530sungwy wants to merge 1 commit into
sungwy wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes PyIceberg’s decimal type parsing more permissive by allowing optional whitespace around decimal parameters, aligning behavior with other Iceberg language implementations.
Changes:
- Update the decimal type parsing regex to tolerate whitespace around precision/scale and separators.
- Add unit tests covering multiple whitespace variants for
decimal(P,S)JSON deserialization.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_types.py | Adds parametrized tests to ensure DecimalType deserialization accepts optional whitespace variants. |
| pyiceberg/types.py | Relaxes the decimal parsing regex to allow whitespace around precision/scale and punctuation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from pyiceberg.utils.singleton import Singleton | ||
|
|
||
| DECIMAL_REGEX = re.compile(r"decimal\((\d+),\s*(\d+)\)") | ||
| DECIMAL_REGEX = re.compile(r"decimal\(\s*(\d+)\s*,\s*(\d+)\s*\)") |
geruh
reviewed
Jun 19, 2026
| DECIMAL_REGEX = re.compile(r"decimal\((\d+),\s*(\d+)\)") | ||
| DECIMAL_REGEX = re.compile(r"decimal\(\s*(\d+)\s*,\s*(\d+)\s*\)") | ||
| FIXED = "fixed" | ||
| FIXED_PARSER = ParseNumberFromBrackets(FIXED) |
Member
There was a problem hiding this comment.
Should we align this logic to the other regex too?
private static final Pattern FIXED = Pattern.compile("fixed\\[\\s*(\\d+)\\s*\\]");
private static final Pattern GEOMETRY_PARAMETERS =
Pattern.compile("geometry\\s*(?:\\(\\s*([^)]*?)\\s*\\))?", Pattern.CASE_INSENSITIVE);
private static final Pattern GEOGRAPHY_PARAMETERS =
Pattern.compile(
"geography\\s*(?:\\(\\s*([^,]*?)\\s*(?:,\\s*(\\w*)\\s*)?\\))?", Pattern.CASE_INSENSITIVE);
private static final Pattern DECIMAL =
Pattern.compile("decimal\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)");
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.
Reference: apache/iceberg#16798
Rationale for this change
PyIceberg is a bit more strict in its parsing than the other language implementations. This allows json string representations like
decimal( 9, 2 )like the other libraries.Are these changes tested?
Unit tested
Are there any user-facing changes?
Yes, more permissive metadata parsing by PyIceberg clients.