You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Kousuke Saruta (Jira)" <ji...@apache.org> on 2021/09/11 20:54:00 UTC

[jira] [Commented] (SPARK-28620) Double type returned for float type in Beeline/JDBC

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

Kousuke Saruta commented on SPARK-28620:
----------------------------------------

[~yumwang]
The reason is ColumnValue.floatValue treats float values as double values.
https://github.com/apache/hive/blob/13b958b76973b963f3b497cf42e2bc2965c15e24/service/src/java/org/apache/hive/service/cli/ColumnValue.java#L87-L93

It's because thrift doesn't support float type.
https://thrift.apache.org/docs/types

> Double type returned for float type in Beeline/JDBC
> ---------------------------------------------------
>
>                 Key: SPARK-28620
>                 URL: https://issues.apache.org/jira/browse/SPARK-28620
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 3.0.0
>            Reporter: Yuming Wang
>            Priority: Major
>
> {code:sql}
>   test("SPARK-28620") {
>     withJdbcStatement {
>       statement =>
>         val rs = statement.executeQuery(
>           "SELECT CAST('1.2345678901234e+20' AS FLOAT), CAST('4.56' AS FLOAT)")
>         rs.next()
>         assert(rs.getObject(1).isInstanceOf[java.lang.Double])
>         assert(rs.getObject(2).isInstanceOf[java.lang.Double])
>     }
>   }
> {code}
> This inconsistent with spark-shell and spark-sql:
> {code:sql}
> 0: jdbc:hive2://localhost:10000> SELECT CAST('1.2345678901234e+20' AS FLOAT), CAST('4.56' AS FLOAT);
> +-------------------------------------+----------------------+
> | CAST(1.2345678901234e+20 AS FLOAT)  | CAST(4.56 AS FLOAT)  |
> +-------------------------------------+----------------------+
> | 1.2345679000000001E20               | 4.56                 |
> +-------------------------------------+----------------------+
> 1 row selected (0.268 seconds)
> {code}
> {code:sql}
> spark-sql> SELECT CAST('1.2345678901234e+20' AS FLOAT), CAST('4.56' AS FLOAT);
> 1.2345679E20	4.56
> scala> spark.sql("SELECT CAST('1.2345678901234e+20' AS FLOAT), CAST('4.56' AS FLOAT)").show
> +----------------------------------+-------------------+
> |CAST(1.2345678901234e+20 AS FLOAT)|CAST(4.56 AS FLOAT)|
> +----------------------------------+-------------------+
> |                      1.2345679E20|               4.56|
> +----------------------------------+-------------------+
> {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