[
https://issues.apache.org/jira/browse/CALCITE-6419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17850508#comment-17850508
]
xiong duan commented on CALCITE-6419:
-------------------------------------
Fixed in
[b9455ef|https://github.com/apache/calcite/commit/b9455ef08ddc948b74037d38e18809ad4ae83ef3].
Thanks for the review [~eveywu] .
> Invalid unparse for VARCHAR without precision in HiveSqlDialect And
> SparkSqlDialect
> -----------------------------------------------------------------------------------
>
> Key: CALCITE-6419
> URL: https://issues.apache.org/jira/browse/CALCITE-6419
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Affects Versions: 1.37.0
> Reporter: xiong duan
> Assignee: xiong duan
> Priority: Minor
> Labels: pull-request-available
> Fix For: 1.38.0
>
>
> When we execute SQL in Calcite:
> {code:java}
> select cast(product_id as varchar) from product;
> {code}
> Generage the HiveSQL\SparkSQL:
> {code:java}
> select cast(product_id as varchar) from product;
> {code}
> According to the
> [https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types#LanguageManualTypes-VarcharvarcharVarchar].
> In Hive, the varchar must have a precision.So when unpare VARCHAR without
> precision, I will convert VARCHAR to String. VARCHAR with precison do nothing.
> According to the
> [https://spark.apache.org/docs/latest/sql-ref-datatypes.html].
> In Spark, Same as Hive. But as note, It can only be used in table schema, not
> functions/operators. So I will convert VARCHAR with or without precision to
> String;
> In SparkSQL, VarcharĀ with precision are not effective, but no error and just
> a warning:
> {code:java}
> spark-sql> select cast('value' as varchar(2));
> 24/05/24 16:04:39 WARN CharVarcharUtils: The Spark cast operator does not
> support char/varchar type and simply treats them as string type. Please use
> string type directly to avoid confusion. Otherwise, you can set
> spark.sql.legacy.charVarcharAsString to true, so that Spark treat them as
> string type as same as Spark 3.0 and earlier
> value
> Time taken: 2.797 seconds, Fetched 1 row(s){code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)