srielau commented on code in PR #45819:
URL: https://github.com/apache/spark/pull/45819#discussion_r1559602846
##########
sql/core/src/test/scala/org/apache/spark/sql/CollationSuite.scala:
##########
@@ -645,6 +646,34 @@ class CollationSuite extends DatasourceV2SQLBase with
AdaptiveSparkPlanHelper {
},
errorClass = "COLLATION_MISMATCH.IMPLICIT"
)
+
+ // check if substring passes through implicit collation
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"SELECT substr('a' COLLATE UNICODE, 0, 1) == substr('b' COLLATE
UNICODE_CI, 0, 1)")
+ },
+ errorClass = "COLLATION_MISMATCH.IMPLICIT"
+ )
+
+ checkAnswer(spark.sql("SELECT collation(:var1 || :var2)",
+ Map(
+ "var1" -> Literal.create("a", StringType(1)),
+ "var2" -> Literal.create("b", StringType(2))
+ )
+ ),
+ Seq(Row("UTF8_BINARY"))
+ )
+
+ withSQLConf(SqlApiConf.DEFAULT_COLLATION -> "UNICODE") {
+ checkAnswer(spark.sql("SELECT collation(:var1 || :var2)",
+ Map(
+ "var1" -> Literal.create("a", StringType(1)),
+ "var2" -> Literal.create("b", StringType(2))
+ )
+ ),
+ Seq(Row("UNICODE"))
+ )
+ }
Review Comment:
I don't know your internal design (and I shouldn't need to), so I won't
comment on that.
But these examples seem correct. What is this 1/2 business in StringType()
about?
Basically the user has two choices:
* say nothing: parameter marker goes with DEFAULT and looses against columns
* explicitly collate: parameter marker goes with explicit collation and wins
against columns.
And if you re-use the same marker in multiple places you can choose
differently.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]