You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Takeshi Yamamuro (Jira)" <ji...@apache.org> on 2019/12/29 09:10:00 UTC

[jira] [Updated] (SPARK-29616) Bankers' rounding for double types

     [ https://issues.apache.org/jira/browse/SPARK-29616?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Takeshi Yamamuro updated SPARK-29616:
-------------------------------------
    Parent Issue: SPARK-30375  (was: SPARK-27764)

> Bankers' rounding for double types
> ----------------------------------
>
>                 Key: SPARK-29616
>                 URL: https://issues.apache.org/jira/browse/SPARK-29616
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SQL
>    Affects Versions: 3.0.0
>            Reporter: Takeshi Yamamuro
>            Priority: Trivial
>
> PostgreSQL uses banker's rounding mode for double types;
> {code}
> postgres=# select * from t;
>  a | b 
> -----+-----
>  0.5 | 0.5
>  1.5 | 1.5
>  2.5 | 2.5
>  3.5 | 3.5
>  4.5 | 4.5
> (5 rows)
> postgres=# \d t
>  Table "public.t"
>  Column | Type | Collation | Nullable | Default 
> --------+------------------+-----------+----------+---------
>  a | double precision | | | 
>  b | numeric(2,1) | | |
> postgres=# select round(a), round(b) from t;
>  round | round 
> -------+-------
>  0 | 1
>  2 | 2
>  2 | 3
>  4 | 4
>  4 | 5
> (5 rows)
> {code}
>  
> In the master;
> {code}
> scala> sql("select * from t").show
> +---+---+
> | a| b|
> +---+---+
> |0.5|0.5|
> |1.5|1.5|
> |2.5|2.5|
> |3.5|3.5|
> |4.5|4.5|
> +---+---+
> scala> sql("select * from t").printSchema
> root
>  |-- a: double (nullable = true)
>  |-- b: decimal(2,1) (nullable = true)
> scala> sql("select round(a), round(b) from t").show()
> +-----------+-----------+
> |round(a, 0)|round(b, 0)|
> +-----------+-----------+
> | 1.0| 1|
> | 2.0| 2|
> | 3.0| 3|
> | 4.0| 4|
> | 5.0| 5|
> +-----------+-----------+
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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