Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyiceberg/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from pyiceberg.utils.parsing import ParseNumberFromBrackets
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*\)")
FIXED = "fixed"
FIXED_PARSER = ParseNumberFromBrackets(FIXED)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we align this logic to the other regex too?

https://github.com/apache/iceberg/blob/41c8ee43b46017843b304241d250737fd10837af/api/src/main/java/org/apache/iceberg/types/Types.java#L66-L73

  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*\\)");


Expand Down
15 changes: 15 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,21 @@ def test_deserialization_decimal() -> None:
assert decimal.scale == 25


@pytest.mark.parametrize(
"decimal_str",
[
"decimal(9,2)",
"decimal(9, 2)",
"decimal( 9, 2 )",
"decimal( 9 , 2 )",
"decimal(9 ,2)",
],
)
def test_deserialization_decimal_optional_whitespace(decimal_str: str) -> None:
# Readers accept optional whitespace around parameters and the separator.
assert DecimalType.model_validate_json(f'"{decimal_str}"') == DecimalType(9, 2)


def test_deserialization_decimal_failure() -> None:
with pytest.raises(ValidationError) as exc_info:
_ = DecimalType.model_validate_json('"decimal(abc, def)"')
Expand Down