Repository navigation
Add Variant integer-to-decimal and float-to-decimal benchmarks - #11416
Merged
Merged
Conversation
Jefffrey
approved these changes
Oct 7, 2026
Contributor
|
thanks @sdf-jkl |
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]>
adriangb
pushed a commit
to pydantic/arrow-rs
that referenced
this pull request
Oct 17, 2026
# Which issue does this PR close? Follow-up to apache#11416. # Rationale for this change The existing `variant_get` decimal benchmarks cover integer and floating-point inputs, but not strings. These cases provide a baseline for measuring changes to string parsing and decimal conversion. # What changes are included in this PR? Add six benchmarks covering four conversion paths: - Short strings to Decimal32 in safe and strict modes. - Strings longer than Variant's 63-byte short-string limit to Decimal128 in safe and strict modes. - Wide values to Decimal256, exercising accumulation beyond the Decimal128 range. - Strings to Decimal256 with a negative scale, exercising the additional integer-digit scan and scale-down path. Fixtures contain 8,192 unshredded Variant rows with approximately 10% nulls and a fixed RNG seed. They reuse the existing `bench_variant_get_decimal` helper, with fixture construction outside timing. # Are these changes tested? This PR adds benchmarks only. All six cases were smoke-tested on upstream main (`4dc6bc25f3`). Formatting and whitespace checks pass. No library behavior changes or additional unit tests are included. # Are there any significant user-facing changes? No. # AI usage Developed with assistance from OpenAI Codex for implementation, validation, and this description.
10 of 30 tasks
5 tasks
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?
variant_getconverts floats and doubles to decimals without checking the target precision #10795 and variant_get converts integers to decimals without consistently checking target precision #11309.Rationale for this change
The existing
variant_getbenchmarks do not cover integer or floating-point conversion to decimals. These cases provide a baseline for measuring changes to precision validation and scaling behavior.What changes are included in this PR?
Add 16 cases covering successful safe/strict conversions, scaling, Decimal256 output, precision overflow, and non-finite floating-point inputs.
Fixtures contain 8,192 unshredded Variant rows with approximately 10% nulls and a fixed RNG seed. They reuse the existing benchmark helper, with fixture construction outside timing.
Float precision-overflow cases run before and after #11302, although their outputs differ: the fix replaces out-of-precision values with nulls.
Are these changes tested?
This PR adds benchmarks only. All 16 cases were smoke-tested and measured against #11302 and its base. No library behavior changes or additional unit tests are included.
Are there any significant user-facing changes?
No.
AI usage
Developed with assistance from OpenAI Codex for implementation, validation, and this description.