uros-db commented on code in PR #46040:
URL: https://github.com/apache/spark/pull/46040#discussion_r1565606851
##########
sql/core/src/test/scala/org/apache/spark/sql/CollationStringExpressionsSuite.scala:
##########
@@ -163,6 +163,155 @@ class CollationStringExpressionsSuite
})
}
+ test("Support Left/Right/Substr with implicit collation") {
+ case class SubstringTestCase(query: String, collation: String, result: Row)
+ val longString = "In the course of human events"
+ val checks = Seq("utf8_binary_lcase", "utf8_binary", "unicode",
"unicode_ci").flatMap(
+ c => Seq(
+ SubstringTestCase(s"select left(left('$longString' collate " + c + ",
5), 1)", c, Row("I")),
+ SubstringTestCase(
+ s"select right(right('$longString' collate " + c + ", 5), 1)", c,
Row("s")),
+ SubstringTestCase(
+ s"select substr(substr('$longString' collate " + c + ", 4), 2)", c,
+ Row("he course of human events"))
+ )
+ )
+
+ checks.foreach { check =>
+ // Result & data type
+ checkAnswer(sql(check.query), check.result)
+
assert(sql(check.query).schema.fields.head.dataType.sameType(StringType(check.collation)))
+ }
+ }
Review Comment:
I think this test is not needed
for the scope of this ticket (adding collation awareness to a string
expression), it doesn't matter where the collationId came from (explicit or
implicit), what matters is can the expression handle it properly
for example: if `left('In the course of human events' collate unicode, 5)`
returns proper result value (`'In th'`) and type (`StringType(3)`), then
calling left on that resulting string is no different than calling `left('In
th' collate unicode, 1)`
--
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]