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/10/27 23:58:00 UTC
[jira] [Created] (SPARK-29616) Bankers' rounding for double types
Takeshi Yamamuro created SPARK-29616:
----------------------------------------
Summary: Bankers' rounding for double types
Key: SPARK-29616
URL: https://issues.apache.org/jira/browse/SPARK-29616
Project: Spark
Issue Type: Improvement
Components: SQL
Affects Versions: 3.0.0
Reporter: Takeshi Yamamuro
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