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

Dongjoon Hyun updated SPARK-23774:
----------------------------------
    Affects Version/s: 2.1.2

> `Cast` to CHAR/VARCHAR should truncate the values
> -------------------------------------------------
>
>                 Key: SPARK-23774
>                 URL: https://issues.apache.org/jira/browse/SPARK-23774
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.1.2, 2.2.1, 2.3.0
>            Reporter: Dongjoon Hyun
>            Priority: Major
>
> This issue aims to fix the following `CAST` behavior on `CHAR/VARCHAR` types.
> Since HiveStringType is used only in parsing, this PR is also about parsing.
> *Spark*
> {code}
> scala> sql("SELECT CAST('123' AS CHAR(1)), CAST('123' AS VARCHAR(1))").show
> +-------------------+-------------------+
> |CAST(123 AS STRING)|CAST(123 AS STRING)|
> +-------------------+-------------------+
> |                123|                123|
> +-------------------+-------------------+
> scala> sql("SELECT CAST('123' AS CHAR(0)), CAST('123' AS VARCHAR(0))").show
> +-------------------+-------------------+
> |CAST(123 AS STRING)|CAST(123 AS STRING)|
> +-------------------+-------------------+
> |                123|                123|
> +-------------------+-------------------+
> {code}
> *Hive*
> {code}
> hive> SELECT CAST('123' AS CHAR(1)), CAST('123' AS VARCHAR(1));
> OK
> 1     1
> hive> SELECT CAST('123' AS CHAR(0)), CAST('123' AS VARCHAR(0));
> FAILED: RuntimeException Char length 0 out of allowed range [1, 255]
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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

Reply via email to