You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by 10110346 <gi...@git.apache.org> on 2017/05/22 08:48:48 UTC

[GitHub] spark pull request #18059: [SPARK-20834][SQL]TypeCoercion:In case 1,loss of ...

GitHub user 10110346 opened a pull request:

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

    [SPARK-20834][SQL]TypeCoercion:In case 1,loss of precision is not acceptable

    ## What changes were proposed in this pull request?
    spark-sql>select if(true, 123456789, cast(1.23 as float));
    spark-sql>1.23456792E8
    select if(true, 123456789012345678, cast(1.23 as double));
    spark-sql>1.2345678901234568E17
    For these two cases, the result is not we expected, it lost precision.
     I think these conversion rules can improve, such as `IntegerType` -> 'FloatType',   `LongType` -> 'FloatType',   `LongType` ->'DoubleType' ,
    
    ## How was this patch tested?
    unit test cases


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

    $ git pull https://github.com/10110346/spark wip-lx-0523

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

    https://github.com/apache/spark/pull/18059.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 #18059
    
----
commit 0e5a78b00587216e6c64d5cadeb531470a7213d1
Author: liuxian <li...@zte.com.cn>
Date:   2017-05-22T08:05:01Z

    TypeCoercion:In case 1,loss of precision is not acceptable

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    can you check other databases and see if this is common? Personally I think the current behavior is reasonable, always using double seems not a good choice.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by 10110346 <gi...@git.apache.org>.
Github user 10110346 commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    ok,I will close it,thanks @cloud-fan 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by 10110346 <gi...@git.apache.org>.
Github user 10110346 commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    Could you help to review it ? thanks @hvanhovell  @cloud-fan 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by 10110346 <gi...@git.apache.org>.
Github user 10110346 commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    I think we should try our best to ensure accuracy, no matter what scenario @wzhfy 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    Then I don't think we can change this behavior, or users from hive will be confused.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by 10110346 <gi...@git.apache.org>.
Github user 10110346 commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    @cloud-fan The current behavior always using `float` ,   but using `double`  can  reduce loss of precision,so ,I think using `double` will be better


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion: In case 1,loss of precis...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    Can one of the admins verify this patch?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    can you check with Hive? Hive compatibility is important for us.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision ...

Posted by 10110346 <gi...@git.apache.org>.
Github user 10110346 closed the pull request at:

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


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by 10110346 <gi...@git.apache.org>.
Github user 10110346 commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    I have tested in MYSQL, the result datatype seems to be `decimalType`:
    mysql> desc  test;
    +------------+---------+------+-----+---------+-------+
    | Field      | Type    | Null | Key | Default | Extra |
    +------------+---------+------+-----+---------+-------+
    | inttest  | int(11) | YES  |     | NULL    |       |
    | doubletest | double  | YES  |     | NULL    |       |
    | floattest  | float   | YES  |     | NULL    |       |
    +------------+---------+------+-----+---------+-------+
    mysql> select * from test;
    +-----------+------------+-----------+
    | inttest      | doubletest | floattest |
    +-----------+------------+-----------+
    | 123456789 |     3.1415 |    3.1416 |
    +-----------+------------+-----------+
    
    mysql> select if(true, inttest, floattest) from test;
    +--------------------------+
    | if(true, inttest, floattest) |
    +--------------------------+
    |                123456789 |
    +--------------------------+


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    BTW I'm still not convinced to use double, as MySQL uses decimal


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by 10110346 <gi...@git.apache.org>.
Github user 10110346 commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    @cloud-fan  Hive use Float:
    select if(true, 123456789, cast(1.23 as float));
    +------------------------------------------------------------+--+
    | (IF(true, CAST(123456789 AS FLOAT), CAST(1.23 AS FLOAT)))  |
    +------------------------------------------------------------+--+
    | 1.23456792E8                                               |
    +------------------------------------------------------------+--+


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #18059: [SPARK-20834][SQL]TypeCoercion:loss of precision when wi...

Posted by wzhfy <gi...@git.apache.org>.
Github user wzhfy commented on the issue:

    https://github.com/apache/spark/pull/18059
  
    If user wants a precise result, why not use deciaml? float and double are both imprecise.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org