mihailom-db commented on code in PR #46474: URL: https://github.com/apache/spark/pull/46474#discussion_r1599507122
########## sql/core/src/test/scala/org/apache/spark/sql/CollationSuite.scala: ########## @@ -851,6 +852,30 @@ class CollationSuite extends DatasourceV2SQLBase with AdaptiveSparkPlanHelper { } } + test("SPARK-47972: Cast expression limitation for collations") { + checkError( + exception = intercept[ParseException] + (sql("SELECT cast(1 as string collate unicode)")), + errorClass = "UNSUPPORTED_DATATYPE", + parameters = Map( + "typeName" -> toSQLType(StringType("UNICODE"))), + context = + ExpectedContext(fragment = s"cast(1 as string collate unicode)", start = 7, stop = 39) + ) + + checkError( + exception = intercept[ParseException] + (sql("SELECT 'A' :: string collate unicode")), + errorClass = "UNSUPPORTED_DATATYPE", + parameters = Map( + "typeName" -> toSQLType(StringType("UNICODE"))), + context = ExpectedContext(fragment = s"'A' :: string collate unicode", start = 7, stop = 35) + ) + + checkAnswer(sql(s"SELECT cast(1 as string)"), Seq(Row("1"))) + checkAnswer(sql(s"SELECT cast('A' as string)"), Seq(Row("A"))) + } Review Comment: I can add a test for this, but it should return a string "1" collated with UNICODE collation. The aim of this PR is to block usage of `STRING COLLATE collation_name` in cast, all previous usage for default collation stay the same. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org