sdf-jkl opened a new pull request, #11302: URL: https://github.com/apache/arrow-rs/pull/11302
# Which issue does this PR close? Closes #10795. # Rationale for this change `variant_get` converts floats and doubles to decimals without checking the target precision. For example, converting `12345.678` to `Decimal32(5, 2)` produces `12345.68`, even though the largest allowed value is `999.99`. Arrow's array cast already rejects this value. Centralize the precision check in a shared scalar conversion, following the approach used for string-to-decimal parsing in #10850, so callers do not need to remember a separate validation step. # What changes are included in this PR? - Add `float_to_decimal(input, precision, scale)`, which checks the target parameters and the scaled, rounded value. - Share the checked conversion between the Arrow array cast and `variant_get`. Safe array casts discard failures without allocating error messages; strict casts retain their existing diagnostics. - Deprecate `single_float_to_decimal` and make it delegate to the checked conversion using the decimal type's maximum precision. # Are these changes tested? Extended the existing `variant_get` safe/strict overflow tests with float and double inputs, including overflow caused by rounding. Added scalar API tests across all four decimal widths, invalid parameters, non-finite values, and maximum-precision checks for the deprecated helper. Validation on current upstream main: - `cargo fmt --all -- --check` - `cargo clippy -p arrow-cast -p parquet-variant-compute --all-targets --all-features -- -D warnings` - `cargo test -p arrow-cast -p parquet-variant-compute --all-features`: 843 unit, integration, and doc tests passed. Benchmarks have not been run. # Are there any user-facing changes? `variant_get` now returns null for float-to-decimal precision overflow in safe mode and an error in strict mode. The new scalar API is public. The deprecated helper keeps its signature but now rejects values that fit the backing integer and exceed the decimal type's maximum precision, such as `1_000_000_000` for Decimal32. Float-to-decimal array casts now validate precision and scale before processing values. # AI usage Developed with assistance from OpenAI Codex for implementation, tests, and the PR description. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
