Skip to content

fix: support decimal datum conversion by precision#2508

Open
abnobdoss wants to merge 2 commits into
apache:mainfrom
abnobdoss:decimal-datum-precision-clean
Open

fix: support decimal datum conversion by precision#2508
abnobdoss wants to merge 2 commits into
apache:mainfrom
abnobdoss:decimal-datum-precision-clean

Conversation

@abnobdoss
Copy link
Copy Markdown

@abnobdoss abnobdoss commented May 26, 2026

Which issue does this PR close?

  • Closes #.

What changes are included in this PR?

This fixes decimal datum precision handling in two places.

First, Datum::to() can now convert between decimal types with the same scale and different precision, as long as the value fits the target precision. This is needed when a decimal literal is created before the target column precision is known.

Second, this fixes a correctness issue in Datum::decimal_with_precision. It previously checked whether the mantissa fit the storage byte width for the requested precision, but that could accept values that exceeded the
declared decimal precision. It now checks the mantissa’s decimal digit count directly. For example, 0.42 has mantissa 42, so it does not fit decimal(1, 2).

Scale conversion remains out of scope. Decimal conversions with different source and target scales still return DataInvalid.

Are these changes tested?

Yes. This adds unit coverage for decimal precision calculation and decimal datum conversion.

Validation run:

cargo fmt --check
cargo test -p iceberg test_decimal_precision
cargo test -p iceberg test_datum_to_decimal_
cargo test -p iceberg test_datum_decimal_with_precision_
cargo clippy -p iceberg --tests -- -D warnings
Was generative AI tooling used to co-author this PR?

Yes.

@abnobdoss abnobdoss force-pushed the decimal-datum-precision-clean branch from 904a5e6 to 6805d7b Compare May 26, 2026 02:00
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.

1 participant