Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUDIT] [SPARK-45786] Inaccurate Decimal multiplication and division results #9859

Closed
tgravescs opened this issue Nov 27, 2023 · 2 comments · Fixed by #9962
Closed

[AUDIT] [SPARK-45786] Inaccurate Decimal multiplication and division results #9859

tgravescs opened this issue Nov 27, 2023 · 2 comments · Fixed by #9962
Assignees
Labels
audit_3.4.2 Audit related tasks for 3.4.2 audit_3.5.1 Audit related tasks for 3.5.1 audit_4.0.0 Audit related tasks for 4.0.0 bug Something isn't working

Comments

@tgravescs
Copy link
Collaborator

Describe the bug
https://issues.apache.org/jira/browse/SPARK-45786 fixes inaccurate decimal multiplication and division in Spark. This looks like a dup of https://issues.apache.org/jira/browse/SPARK-40129.

I believe we explicitly copied the behavior of Spark for the multiplication side so we should look to see if we need to change it.

@tgravescs tgravescs added bug Something isn't working ? - Needs Triage Need team to review and classify audit_3.4.2 Audit related tasks for 3.4.2 audit_3.5.1 Audit related tasks for 3.5.1 audit_4.0.0 Audit related tasks for 4.0.0 labels Nov 27, 2023
@tgravescs
Copy link
Collaborator Author

Note a repro case of this is:

pyspark
 
from pyspark.sql.functions import *
df = spark.createDataFrame([("-8533444864753048107770677711.1312637916", )], ["col_1"])
df = df.withColumn("col_2", lit(-12).cast("decimal(38,10)"))
df = df.withColumn("col_3", col("col_2").cast("decimal(38,10)") * col("col_1").cast("decimal(38,10)"))
df.show(truncate=False)
 
(This was run just on my CPU with Apache Spark) before the fix:
+----------------------------------------+--------------+-------------------------------------+
|col_1                                   |col_2         |col_3                                |
+----------------------------------------+--------------+-------------------------------------+
|-8533444864753048107770677711.1312637916|-12.0000000000|102401338377036577293248132533.575166|
+----------------------------------------+--------------+-------------------------------------+
 
The value after the fix is:
 got  102401338377036577293248132533.575165

@razajafri
Copy link
Collaborator

razajafri commented Dec 12, 2023

There is a follow-on bug that specifically deals with Decimal division on Spark versions 330db+ and 340+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit_3.4.2 Audit related tasks for 3.4.2 audit_3.5.1 Audit related tasks for 3.5.1 audit_4.0.0 Audit related tasks for 4.0.0 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants