Skip to content

Add focused float-to-decimal cast benchmarks - #11343

Merged
sdf-jkl merged 4 commits into
apache:mainfrom
sdf-jkl:codex/float-decimal-cast-benchmarks
Oct 5, 2026
Merged

sdf-jkl merged 4 commits into
apache:mainfrom
sdf-jkl:codex/float-decimal-cast-benchmarks

Conversation

@sdf-jkl

@sdf-jkl sdf-jkl commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

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:

  • Float32 to Decimal32 in safe and strict mode.
  • Float64 to Decimal128 in strict mode, complementing the existing safe case.
  • Float64 to Decimal256 with a negative scale, exercising its separate float-to-i256 conversion.
  • Precision overflow in safe mode, combining direct and rounding-induced overflow while processing the whole array.

Fixtures contain 8192 rows with approximately 10% nulls. Fixture construction runs outside the timed loop. Use the existing add_benchmark and individual bench_function calls, following #11313.

Are these changes tested?

Validation before removing the fixture assertions:

  • All five benchmark smoke cases pass on upstream main (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 warnings passes, with the existing unknown clippy::assert_is_empty lint warning. Checking dependencies also encounters an existing clippy::chunks_exact_to_as_chunks lint in arrow-row.
  • Ran the same benchmarks on main and fix: move float-to-decimal precision validation inside the cast kernel #11302 using Rust 1.98.1, identical dependencies, and CPU affinity. Each revision was measured twice in main / PR / PR / main order, with 50 samples, a one-second warmup, and a two-second measurement per case.

After removing the fixture assertions, cargo +1.98.1 fmt --all -- --check and git diff --check pass. 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.

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Oct 2, 2026
@Jefffrey Jefffrey added the development-process Internal changes; PRs with this label are excluded from changelog label Oct 4, 2026
@sdf-jkl
sdf-jkl added this pull request to the merge queue Oct 5, 2026
@github-merge-queue
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.
@sdf-jkl
sdf-jkl enabled auto-merge October 5, 2026 21:35
@sdf-jkl
sdf-jkl added this pull request to the merge queue Oct 5, 2026
Merged via the queue into apache:main with commit 934e16e Oct 5, 2026
31 checks passed
@sdf-jkl

sdf-jkl commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

Thanks @Jefffrey

@sdf-jkl
sdf-jkl deleted the codex/float-decimal-cast-benchmarks branch October 5, 2026 23:00
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate development-process Internal changes; PRs with this label are excluded from changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants