Skip to content

Add Variant integer-to-decimal and float-to-decimal benchmarks - #11416

Merged
Jefffrey merged 1 commit into
apache:mainfrom
sdf-jkl:codex/variant-decimal-benchmarks
Oct 7, 2026
Merged

Jefffrey merged 1 commit into
apache:mainfrom
sdf-jkl:codex/variant-decimal-benchmarks

Conversation

@sdf-jkl

@sdf-jkl sdf-jkl commented Oct 6, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

The existing variant_get benchmarks 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.

@Jefffrey Jefffrey added the development-process Internal changes; PRs with this label are excluded from changelog label Oct 7, 2026
@Jefffrey
Jefffrey added this pull request to the merge queue Oct 7, 2026
@Jefffrey

Jefffrey commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

thanks @sdf-jkl

Merged via the queue into apache:main with commit 29ec1c0 Oct 7, 2026
24 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

development-process Internal changes; PRs with this label are excluded from changelog parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants