Repository navigation
Accept INT32 and INT64 decimals for wider decimal columns in add_files - #4615
Open
rahulsmahadev wants to merge 1 commit into
Open
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
StatsAggregator compared a decimal column's Parquet physical type with the one PyIceberg writes for the table's precision, so add_files rejected a decimal(18, 2) file stored as INT64 for a decimal(38, 2) column. Allow INT32, INT64 and FIXED_LEN_BYTE_ARRAY for any decimal, as the comment above the check says; the statistics of all three are already decoded with the column's scale. Co-authored-by: Isaac <no-reply@databricks.com>
Fokko
approved these changes
Dec 4, 2026
Fokko
left a comment
Contributor
There was a problem hiding this comment.
Good catch @rahulsmahadev! Verified that Java's ParquetConversions.convertValue accepts INT32, INT64 and FIXED_LEN_BYTE_ARRAY decimals at any precision, so this aligns add_files with Spark. Thanks for the tests covering the new pass cases and the still-rejected BYTE_ARRAY case. 👍
This branch has not been deployed
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.
Rationale for this change
Bug:
add_filesaccepts a file whosedecimal(18, 2)column maps to adecimal(38, 2)table column, since widening the precision is a valid promotion, and then fails while collecting the column's bounds:StatsAggregatorcompares the file's physical type with the one PyIceberg writes for the table's precision. But a file keeps the storage of its own precision: the spec storesdecimal(P, S)asint32for P <= 9 andint64for P <= 18, and PyIceberg, Iceberg Java, Spark, DuckDB and Polars write it that way. So an INT32 or INT64 decimal fails once the table column's precision is above 18, for example after widening it. #2515 (for #2057) only allowed the opposite case, FIXED_LEN_BYTE_ARRAY for a small precision.Fix: allow INT32, INT64 and FIXED_LEN_BYTE_ARRAY for any decimal, as the comment above the check already says (kevinjqliu asked for it on #2515).
data_file_statistics_from_parquet_metadataalready decodes all three, and decimal bounds do not depend on the precision (minimal two's complement bytes). The FIXED_LEN_BYTE_ARRAY exception now only applies to decimals; other types never reached it fromadd_files, because the schema check rejects them first. The TODO to reuse the promotion logic stays: a decimal's storage does not follow from its type even without a promotion (#2057).Java: Spark's
add_filesprocedure gets the metrics fromParquetUtil.fileMetrics(throughSparkTableUtilandTableMigrationUtil.listPartition), which uses the file's own schema, andParquetConversions.convertValuereads decimal statistics stored as INT32, INT64, FIXED_LEN_BYTE_ARRAY or BINARY at any precision. This PR fixes the physical type check in front of PyIceberg's version of that conversion. One difference remains:Are these changes tested?
Yes, in
tests/io/test_pyarrow.py:test_add_files_int_stored_decimal_into_wider_decimal(INT32 intodecimal(20, 2)and INT64 intodecimal(38, 2): bounds, pruning and rows) fails on main withValueError: Unexpected physical type INT32 for decimal(20, 2), expected FIXED_LEN_BYTE_ARRAY. The new cases intest_stats_aggregator_conditionally_allowed_types_passalso fail on main withUnexpected physical type, and theLongType()case intest_stats_aggregator_physical_type_does_not_match_expected_raise_errorfails because main does not raise. The BYTE_ARRAY case passes on main too; it checks that the new branch still rejects a storage the decoder cannot read. All pass with this change.Are there any user-facing changes?
Yes,
add_filesaccepts these files instead of raising.Please add the
changeloglabel.This pull request and its description were written by Isaac.