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: 2 additions & 0 deletions pyiceberg/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ class DecimalType(PrimitiveType):
root: tuple[int, int]

def __init__(self, precision: int, scale: int) -> None:
if precision > 38:
raise ValueError(f"Decimals with precision larger than 38 are not supported: {precision}")
super().__init__(root=(precision, scale))

@model_serializer
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
FloatType(),
DoubleType(),
DecimalType(10, 2),
DecimalType(100, 2),
DecimalType(38, 2),
StringType(),
DateType(),
TimeType(),
Expand Down
9 changes: 9 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ def test_decimal_type() -> None:
assert type_var == pickle.loads(pickle.dumps(type_var))


def test_decimal_type_rejects_precision_over_38() -> None:
# The Iceberg spec requires decimal precision to be 38 or less; the Java
# reference implementation raises for precision > 38. See issue #3583.
with pytest.raises(ValueError, match="precision larger than 38 are not supported: 39"):
DecimalType(39, 0)
# Boundary: precision exactly 38 is still valid.
assert DecimalType(38, 0).precision == 38


def test_struct_type() -> None:
type_var = StructType(
NestedField(1, "optional_field", IntegerType(), required=True),
Expand Down