Skip to content

fix(iceberg): normalize decimal datum precision#5

Draft
abnobdoss wants to merge 1 commit into
predicate-bind-regression-testsfrom
decimal-datum-precision-normalization
Draft

fix(iceberg): normalize decimal datum precision#5
abnobdoss wants to merge 1 commit into
predicate-bind-regression-testsfrom
decimal-datum-precision-normalization

Conversation

@abnobdoss
Copy link
Copy Markdown
Owner

@abnobdoss abnobdoss commented May 24, 2026

What

Allows Datum::to() to convert decimal Datum values between decimal types with the same scale when the unscaled value fits the target precision.

This keeps scale conversion out of scope. A decimal with a different target scale still returns DataInvalid.

Why

Datum::decimal_from_str() creates decimal literals with max precision 38. Binding those literals against ordinary decimal columns such as decimal(9, 2) fails even when the value fits and the scale matches.

This change lets bind-time conversion normalize the precision while preserving the decimal value. The precision check is shared with Datum::decimal_with_precision, so direct construction and bind-time conversion enforce the same decimal digit-precision rule.

Tests

Adds coverage for:

  • narrowing decimal precision when scale matches
  • widening decimal precision when scale matches
  • rejecting target precision that is too narrow
  • rejecting a value that fits required storage bytes but exceeds decimal digit precision
  • accepting a single-digit unscaled value for decimal(1, 2)
  • enforcing digit precision in Datum::decimal_with_precision
  • rejecting scale changes
  • binding Datum::decimal_from_str("3.14") against decimal(9, 2) after normalization

Validation run:

cargo fmt --check
cargo test -p iceberg test_datum_to_decimal_
cargo test -p iceberg test_datum_decimal_with_precision_
cargo test -p iceberg test_bind_decimal
cargo clippy -p iceberg --tests -- -D warnings

@abnobdoss abnobdoss force-pushed the decimal-datum-precision-normalization branch 3 times, most recently from 6a62ef7 to f471f4f Compare May 25, 2026 19:25
@abnobdoss abnobdoss force-pushed the decimal-datum-precision-normalization branch from f471f4f to 9f9b087 Compare May 25, 2026 21:26
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