GitHub user gatorsmile opened a pull request:

    https://github.com/apache/spark/pull/18297

    [SPARK-20211][SQL][Backport-2.2] Fix the Precision and Scale of Decimal 
Values when the Input is BigDecimal between -1.0 and 1.0 

    ### What changes were proposed in this pull request?
    
    
    This PR is to backport https://github.com/apache/spark/pull/18244 to 2.2
    
    ---
    
    The precision and scale of decimal values are wrong when the input is 
BigDecimal between -1.0 and 1.0. 
    
    The BigDecimal's precision is the digit count starts from the leftmost 
nonzero digit based on the [JAVA's BigDecimal 
definition](https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html).
 However, our Decimal decision follows the database decimal standard, which is 
the total number of digits, including both to the left and the right of the 
decimal point. Thus, this PR is to fix the issue by doing the conversion.
    
    Before this PR, the following queries failed:
    ```SQL
    select 1 > 0.0001
    select floor(0.0001)
    select ceil(0.0001)
    ```
    
    ### How was this patch tested?
    Added test cases.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/gatorsmile/spark backport18244

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/18297.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #18297
    
----
commit c9e13089dfc5315f88bc3dbb1a3d83ac8ee7d5bb
Author: gatorsmile <[email protected]>
Date:   2017-06-14T06:04:07Z

    fix.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to