chore: allow optional whitespace around parameters similar to other language implementations#3530
chore: allow optional whitespace around parameters similar to other language implementations#3530sungwy wants to merge 1 commit into
Conversation
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*\)") |
| 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) |
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 pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
|
@sungwy can you make the proposed changes and we can hopefully get this merged in? |
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.