Skip to content

Decimal arithmetic dtypes and widening rescale cast#8343

Open
gatesn wants to merge 2 commits into
developfrom
ngates/decimal-arithmetic-dtypes
Open

Decimal arithmetic dtypes and widening rescale cast#8343
gatesn wants to merge 2 commits into
developfrom
ngates/decimal-arithmetic-dtypes

Conversation

@gatesn

@gatesn gatesn commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Binary::return_dtype derives Hive-style result types for decimal + - * / (mirroring arrow-arith's execution-time rules, with precision saturation at the physical width), instead of erroring at plan time. The decimal cast kernel gains widening rescale so expression coercion can align decimal operand types.

Binary::return_dtype derives Hive-style result types for decimal
+ - * / (mirroring arrow-arith's execution-time rules, with precision
saturation at the physical width), instead of erroring at plan time.
The decimal cast kernel gains widening rescale so expression coercion
can align decimal operand types.

Needed by vortex-engine for TPC-H Q1/Q6 decimal expressions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Nicholas Gates <nick@nickgates.com>
@gatesn gatesn requested a review from AdamGS June 10, 2026 20:07
@gatesn gatesn added the changelog/fix A bug fix label Jun 10, 2026
@gatesn gatesn marked this pull request as ready for review June 10, 2026 20:07
@gatesn gatesn requested a review from a team June 10, 2026 20:07
@gatesn gatesn enabled auto-merge (squash) June 10, 2026 20:07
@codspeed-hq

codspeed-hq Bot commented Jun 10, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 11.63%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 2 improved benchmarks
❌ 5 regressed benchmarks
✅ 1521 untouched benchmarks
⏩ 10 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation chunked_bool_canonical_into[(1000, 10)] 20.7 µs 35.4 µs -41.66%
Simulation chunked_varbinview_canonical_into[(1000, 10)] 161.9 µs 198 µs -18.24%
Simulation chunked_varbinview_into_canonical[(1000, 10)] 177.1 µs 213.2 µs -16.89%
Simulation decompress_rd[f64, (100000, 0.01)] 845.9 µs 980.8 µs -13.75%
Simulation decompress_rd[f64, (100000, 0.1)] 845.9 µs 980.7 µs -13.75%
Simulation decompress_rd[f64, (100000, 0.0)] 1,024.6 µs 845 µs +21.25%
Simulation decompress_rd[f32, (100000, 0.0)] 586.8 µs 498.6 µs +17.68%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ngates/decimal-arithmetic-dtypes (9257307) with develop (31167ca)

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@AdamGS AdamGS self-assigned this Jun 10, 2026

@joseph-isaacs joseph-isaacs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very slow?

Comment thread vortex-array/src/arrays/decimal/compute/cast.rs Outdated
Comment thread vortex-array/src/scalar_fn/fns/binary/mod.rs Outdated
Comment thread vortex-array/src/scalar_fn/fns/binary/mod.rs Outdated
Signed-off-by: "Nicholas Gates" <nick@nickgates.com>
Comment on lines +156 to +165

let from_values_type = array.values_type();
if from_values_type == DecimalType::I256 {
vortex_bail!("rescaling i256 decimals is not supported");
}

let to_values_type = DecimalType::smallest_decimal_value_type(&to);
if to_values_type == DecimalType::I256 {
vortex_bail!("rescaling into i256 decimals is not supported");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? given appropriate precision/scale it should be possible.


// Downcasting precision is not yet supported
if to_decimal_dtype.precision() < from_decimal_dtype.precision() {
// The target must retain at least the source's integer digits.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its just a TODO right? Worth opening a ticket or something

/// at the physical width's maximum: vortex lowers precisions
/// `<= i128::MAX_PRECISION` to Arrow `Decimal128` and wider decimals to
/// `Decimal256`.
fn decimal_arithmetic_dtype(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the narrower types?

@AdamGS

AdamGS commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

I think this seems fine, but its worth creating issues for all the remaining gaps. The only thing we have right now is this almost year old issue.


/// Output decimal type of an arithmetic `operator` over two decimal operands.
///
/// Mirrors the Hive-style rules `arrow-arith` applies at execution time

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have widening system, I think its worth spelling it out in the docs or including a permalink or something to a reference

@AdamGS

AdamGS commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

I think its worth expanding the PR description to what's actually here and what isn't so we can map out the follow up work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants