Repository navigation
Add focused float-to-decimal cast benchmarks - #11343
Merged
Merged
Conversation
Jefffrey
approved these changes
Oct 4, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 5, 2026
Resolved with assistance from OpenAI Codex.
Member
Author
|
Thanks @Jefffrey |
ueshin
pushed a commit
to ueshin/apache-arrow-rs
that referenced
this pull request
Oct 15, 2026
apache#11302) # Which issue does this PR close? Closes apache#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 apache#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` while preserving its existing conversion behavior. # 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, and non-finite values. A compatibility regression test verifies that the deprecated helper still accepts values that fit the native integer but exceed decimal precision, while the new API rejects them. Array benchmark coverage is in apache#11343; Variant benchmarks are proposed in apache#11416. # Are there any significant 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 and existing behavior. 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. --------- Co-authored-by: Jeffrey Vo <[email protected]>
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.
Which issue does this PR close?
Part of #10795. Adds benchmark coverage ahead of #11302.
Rationale for this change
The existing float-to-decimal benchmarks cover safe Float64-to-Decimal128 casts with valid and non-finite inputs. They do not isolate Float32 conversion, successful strict casts, Decimal256 conversion, or target-precision overflow, paths affected by sharing checked float-to-decimal conversion between Arrow and Variant in #11302.
What changes are included in this PR?
Add five benchmarks selected for distinct conversion paths:
Fixtures contain 8192 rows with approximately 10% nulls. Fixture construction runs outside the timed loop. Use the existing
add_benchmarkand individualbench_functioncalls, following #11313.Are these changes tested?
Validation before removing the fixture assertions:
26de48deaf) and fix: move float-to-decimal precision validation inside the cast kernel #11302 (15aeeb8098).cargo +1.98.1 fmt --all -- --check.cargo +1.98.1 clippy -p arrow --bench cast_kernels --features test_utils --no-deps -- -D warningspasses, with the existing unknownclippy::assert_is_emptylint warning. Checking dependencies also encounters an existingclippy::chunks_exact_to_as_chunkslint inarrow-row.After removing the fixture assertions,
cargo +1.98.1 fmt --all -- --checkandgit diff --checkpass. A fresh benchmark compile check was blocked by the local disk quota.Are there any user-facing changes?
No. Benchmark additions only.
AI usage
Developed with assistance from OpenAI Codex for the benchmarks, validation, and PR description.