Skip to content

Reject DecimalType with precision larger than 38#3593

Open
kratos0718 wants to merge 2 commits into
apache:mainfrom
kratos0718:fix/decimal-precision-max-38
Open

Reject DecimalType with precision larger than 38#3593
kratos0718 wants to merge 2 commits into
apache:mainfrom
kratos0718:fix/decimal-precision-max-38

Conversation

@kratos0718

Copy link
Copy Markdown

Summary

The Iceberg spec requires decimal precision to be 38 or less ("Scale is fixed, precision must be 38 or less"). Currently DecimalType(39, 0) — and parsing the type string "decimal(39, 0)" — is accepted silently, producing DecimalType(precision=39, scale=0). Precision above 38 isn't representable in decimal's fixed-byte storage, so silently accepting it can corrupt downstream encoding.

The Java reference implementation rejects this: DecimalType.of(39, 0) raises IllegalArgumentException: Decimals with precision larger than 38 are not supported: 39.

Closes #3583.

Change

Validate precision <= 38 in DecimalType.__init__, raising ValueError with the same message as the Java reference. This covers both direct construction and the string-parse path (_parse_decimal_type constructs DecimalType(precision, scale), which routes through __init__).

Test

Added test_decimal_type_rejects_precision_over_38: DecimalType(39, 0) raises, and the boundary DecimalType(38, 0) remains valid.

The Iceberg spec requires decimal precision to be 38 or less, but
DecimalType(39, 0) (and parsing 'decimal(39, 0)') was accepted silently,
producing a value not representable in decimal's fixed-byte storage. Validate
precision <= 38 in DecimalType.__init__, matching the Java reference which
raises for precision > 38.

Closes apache#3583
DecimalType(100, 2) exceeds the spec's max precision of 38 and is now rejected
by the new validation; use the maximum valid precision instead.
@ebyhr

ebyhr commented Jul 2, 2026

Copy link
Copy Markdown
Member

There is an existing PR #3584

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decimal Should Reject precision > 38

2 participants