You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "ZhouDaHong (Jira)" <ji...@apache.org> on 2020/08/14 03:47:00 UTC

[jira] [Commented] (SPARK-21774) The rule PromoteStrings cast string to a wrong data type

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

ZhouDaHong commented on SPARK-21774:
------------------------------------

Hello, you compare the value of a field of string type with the 0 in your sql. Due to the different data types, (the 0 may be judged as boolean type, or 0 as int type).

Therefore, the SQL statement [ select a, B from TB where a = 0 ] cannot get the result you expect.

It is suggested to change to [ select a, B from TB where a ='0' ]

> The rule PromoteStrings cast string to a wrong data type
> --------------------------------------------------------
>
>                 Key: SPARK-21774
>                 URL: https://issues.apache.org/jira/browse/SPARK-21774
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.2.0
>            Reporter: StanZhai
>            Priority: Critical
>              Labels: correctness
>
> Data
> {code}
> create temporary view tb as select * from values
> ("0", 1),
> ("-0.1", 2),
> ("1", 3)
> as grouping(a, b)
> {code}
> SQL:
> {code}
> select a, b from tb where a=0
> {code}
> The result which is wrong:
> {code}
> +----+---+
> |   a|  b|
> +----+---+
> |   0|  1|
> |-0.1|  2|
> +----+---+
> {code}
> Logical Plan:
> {code}
> == Parsed Logical Plan ==
> 'Project ['a]
> +- 'Filter ('a = 0)
>    +- 'UnresolvedRelation `src`
> == Analyzed Logical Plan ==
> a: string
> Project [a#8528]
> +- Filter (cast(a#8528 as int) = 0)
>    +- SubqueryAlias src
>       +- Project [_1#8525 AS a#8528, _2#8526 AS b#8529]
>          +- LocalRelation [_1#8525, _2#8526]
> {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