andygrove opened a new pull request, #4938:
URL: https://github.com/apache/datafusion-comet/pull/4938

   ## Which issue does this PR close?
   
   Part of #4936.
   
   ## Rationale for this change
   
   `DecimalRescaleCheckOverflow` implements the fused `CheckOverflow(Cast(expr, 
Decimal128(p,s)))` used by decimal-to-decimal casts, which are common in 
TPC-DS. It rescales and precision-checks in a single `try_unary` pass, writing 
`i128::MAX` as an overflow sentinel. In legacy (non-ANSI) mode it then always 
ran `null_if_overflow_precision`, a second full pass that allocates a new array 
to convert sentinels into nulls, even when no value overflowed (the common 
case).
   
   ## What changes are included in this PR?
   
   Runs the `null_if_overflow_precision` masking pass only when a sentinel is 
actually present (`result.values().contains(&i128::MAX)`). The check 
short-circuits at the first sentinel, so the overflow path is unaffected, while 
the common no-overflow path skips the extra allocation. ANSI mode never 
produces a sentinel and is unchanged.
   
   Also adds a legacy unit test that mixes valid, overflowing, and null inputs 
(exercising the sentinel fallback with nulls present) and a criterion benchmark.
   
   ## How are these changes tested?
   
   Existing unit tests cover scale-up, scale-down with HALF_UP rounding, 
precision-only checks, overflow nulling (legacy) and raising (ANSI), null 
propagation, and the scalar path. Added a legacy overflow-with-nulls test. 
Output is bit-identical to `main`: when no sentinel is present, 
`null_if_overflow_precision` would have nulled nothing, so skipping it yields 
the same array.
   
   Benchmark (criterion), baseline `main` vs this branch, 8192-row Decimal128 
columns, confirmed across multiple samples:
   
   ```
   decimal_rescale: scale up, no overflow:          13.84 µs -> 10.6 µs   (-23%)
   decimal_rescale: scale up, no overflow, nulls:   20.69 µs -> 15.3 µs   (-26%)
   decimal_rescale: scale down, no overflow:        36.33 µs -> 33.2 µs   
(-8.5%)
   decimal_rescale: sparse overflow:                14.02 µs -> 14.0 µs   
(within noise)
   decimal_rescale: dense overflow:                 16.41 µs -> 16.5 µs   
(within noise)
   decimal_rescale: ansi scale up, no overflow:      7.92 µs ->  7.9 µs   
(within noise)
   ```
   
   The no-overflow shapes (the common case) skip the second allocation; 
overflow shapes short-circuit the sentinel check and run the unchanged masking 
pass.


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to