[ 
https://issues.apache.org/jira/browse/SPARK-59802?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated SPARK-59802:
-----------------------------------
    Labels: pull-request-available  (was: )

> Multiply compact decimals without allocating BigDecimal
> -------------------------------------------------------
>
>                 Key: SPARK-59802
>                 URL: https://issues.apache.org/jira/browse/SPARK-59802
>             Project: Spark
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 4.1.0
>            Reporter: David Mollitor
>            Priority: Minor
>              Labels: pull-request-available
>
> h3. What
> {{Decimal}} keeps small values in a compact {{long}} ({{decimalVal == null}}) 
> and only expands to a {{java.math.BigDecimal}} beyond 18 digits, but 
> {{Decimal.*}} always went through {{toJavaBigDecimal.multiply(..., 
> MATH_CONTEXT)}} with no compact path -- a row-level {{a * b}} on two compact 
> operands allocated two operand {{BigDecimal}}s, a result {{BigDecimal}}, and 
> its {{BigInteger}}.
> Add a compact {{long}} fast path for {{*}}, mirroring the existing same-scale 
> {{+}}/{{-}}: when both operands are compact and the exact product fits the 
> 18-digit compact range (overflow-checked via {{Math.multiplyHigh}}), multiply 
> the unscaled longs directly; otherwise fall back to the existing BigDecimal 
> path.
> h3. Why
> Avoids per-row {{BigDecimal}}/{{BigInteger}} allocation for the common 
> small-decimal case (e.g. multiplying {{decimal(7,2)}} prices/amounts). On a 
> full TPC-DS v1.4 (SF10) JFR run, {{BigDecimal}} allocations attributed to 
> {{Decimal.*}} dropped ~93%. Correctness-neutral (byte-identical): the fast 
> path runs only where no rounding occurs, and high-precision operands 
> (including the SPARK-45786 case) keep the BigDecimal path; {{CheckOverflow}} 
> re-normalizes precision/scale exactly as before.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

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

Reply via email to