-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: Fix incorrect result from casting double to decimal #12600
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
fix: Fix incorrect result from casting double to decimal #12600
Conversation
✅ Deploy Preview for meta-velox canceled.
|
82b0a12
to
26b630b
Compare
@rui-mo sn @mbasmanova could you help review this PR? The CI failure is unrelated. |
Is there an issue about this failure? If not, would you create one and reference it here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yuhta Jimmy, would you help review this fix?
#12603 |
26b630b
to
b64362e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
9caa003
to
968fb09
Compare
@Yuhta , could you please help review this PR? |
@bikramSingh91 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@bikramSingh91 merged this pull request in 76b3235. |
…ubator#12600) Summary: When converting 0.03456789 to DECIMAL(38, 33), the result generated by Velox is inconsistent with Spark and Presto. This discrepancy is caused by precision errors due to long double multiplication. I propose fixing this issue by first converting the result to the target type(int64_t / int128_t) and then applying rescaling. Velox ``` spark.sql("select cast(0.03456789d as decimal(38, 33))").collect res18: Array[org.apache.spark.sql.Row] = Array([0.034567889999999999999845079187456]) ``` Spark ``` spark.sql("select cast(0.03456789d as decimal(38, 33))").collect res16: Array[org.apache.spark.sql.Row] = Array([0.034567890000000000000000000000000]) ``` Presto ``` presto> select cast(0.03456789 as decimal(38, 33)); _col0 ------------------------------------- 0.034567890000000000000000000000000 (1 row) ``` Pull Request resolved: facebookincubator#12600 Reviewed By: kgpai Differential Revision: D71907659 Pulled By: bikramSingh91 fbshipit-source-id: ffaee88c3f1f67a8d0f2e2008550d591ce8b66ca
When converting 0.03456789 to DECIMAL(38, 33), the result generated by Velox is
inconsistent with Spark and Presto. This discrepancy is caused by precision
errors due to long double multiplication. I propose fixing this issue by first
converting the result to the target type(int64_t / int128_t) and then applying rescaling.
Velox
Spark
Presto