spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aman Omer (Jira)" <j...@apache.org>
Subject [jira] [Commented] (SPARK-29616) Bankers' rounding for double types
Date Tue, 05 Nov 2019 06:22:00 GMT

    [ https://issues.apache.org/jira/browse/SPARK-29616?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16967273#comment-16967273
] 

Aman Omer commented on SPARK-29616:
-----------------------------------

cc [~yumwang]

> 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


Mime
View raw message