mbutrovich opened a new pull request, #11426:
URL: https://github.com/apache/arrow-rs/pull/11426

   # Which issue does this PR close?
   
   - Part of #11421.
   
   # Rationale for this change
   
   #11421 proposes replacing the per-row division by a power of ten in decimal 
casts with a precomputed reciprocal. The kernel PRs need benchmarks on `main` 
to report before and after numbers, and the existing cases in 
`arrow/benches/cast_kernels.rs` don't cover the inputs where the methods 
differ. Their [decimal 
arrays](https://github.com/apache/arrow-rs/blob/c7f60c612bd16ca5485cc9acddfd216c10ea9765/arrow/benches/cast_kernels.rs#L84-L114)
 hold non-negative values below 10^9, so every downscale and decimal to integer 
case divides a value of at most 9 digits.
   
   # What changes are included in this PR?
   
   This PR adds a `cast_decimal` benchmark to `arrow-cast` with three groups. 
Every array is built from a fixed seed with a chosen number of digits, and half 
of the values are negative.
   
   - `decimal_downscale` casts 8192 values to a smaller scale. It covers each 
decimal width, `Decimal128` values with 15, 18, 30 and 38 digits, a cast that 
takes the fallible path, and `Decimal256` values with 38 and 60 digits. Three 
cases cast `Decimal256` to `Decimal128(38, 6)` from `Decimal256(41, 20)`, 
`Decimal256(76, 20)` and `Decimal256(76, 40)`, which are the result types of 
`Decimal256` multiplies of `Decimal128(20, 10)`, `Decimal128(38, 10)` and 
`Decimal128(38, 20)` operands. Engines that evaluate a `Decimal128` multiply in 
`Decimal256`, such as Comet before 
[`WideDecimalBinaryExpr`](https://github.com/apache/datafusion-comet/blob/8d0bb01a5a99924024e07c1722e6eddd9260e167/native/spark-expr/benches/wide_decimal.rs#L77-L105),
 run these casts.
   - `decimal_downscale_small` runs one `Decimal128` case and two `Decimal256` 
cases on 1, 16 and 128 values. Building a reciprocal costs more than one 
division, so these cases show where the per-array setup outweighs the per-value 
savings.
   - `decimal_to_int64` casts `Decimal64`, `Decimal128` and `Decimal256` values 
with 18 to 58 digits to `Int64`.
   
   The 8192-value cases run on an array without nulls and on the same values 
with every tenth one null. The cases that can fail also run with `safe: false`, 
because both kernels have a separate loop for it. A strict cast also returns an 
error if a value doesn't fit, so the benchmark can't time the failure path by 
mistake.
   
   # Are these changes tested?
   
   This PR only adds benchmarks.
   
   # Are there any significant user-facing changes?
   
   No.
   
   ## AI Disclosure
   
   I wrote this PR with help from Claude but understand and support the core 
approach, implementation, and test coverage.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to