-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-10215][SQL][WIP]Div of Decimal returns null #8409
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
Conversation
|
what is the datatype of |
|
ok the type of |
|
Yes, the CheckOverflow(xxx, DecimalType(38,38)) will yield null. |
|
Test build #41512 has finished for PR 8409 at commit
|
|
The precision and scale will be calculated based on |
|
Yes, that's why I changed the |
|
If you change |
|
I think the maximum scale we can support should be 18, not 38. As you can see that in |
|
|
@yhuai For Add/Sub/Multiply, we should not lose precision (we can't reduce the scale of result, prefer overflow), but for division, we can't keep all the precision under zero anyway, then we could have a maximum scale, or preserve the range first. From MS SQL Server: https://msdn.microsoft.com/en-us/library/ms190476.aspx To be safe, I think we should only do this for division, or we will lose precision silently for add/sub/multiply (it does overflow in Hive). |
|
@davis, are you suggesting we should change the code in |
|
@davies When we performing an division for 2 decimals with type Decimal(38, 18), the result can be Decimal(77, 57), as @yhuai described above, this probably causes problem when we try to get the That's why I come with the idea to limit the maximum value for |
|
@chenghao-intel Yes. This is how precision of division is determined in Hive: https://github.com/apache/hive/blob/ac755ebe26361a4647d53db2a28500f71697b276/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPDivide.java#L113 |
|
There is another problem here, we promote the precision and scale for integer from (10, 0) to (38, 18), I think we shouldn't do this for add/sub/multiple/division, because we will promote them together in a better way. |
|
@chenghao-intel We could have a small change like this: |
|
Thanks you all for the reply, I am closing this since #8415 is basically solved all of the open questions. |
Seems we respect the scale part of a decimal more than the integral part, which causes incorrect overflow checking(returns null).