uros-db commented on code in PR #46040: URL: https://github.com/apache/spark/pull/46040#discussion_r1565371395
########## sql/core/src/test/scala/org/apache/spark/sql/CollationStringExpressionsSuite.scala: ########## @@ -163,6 +163,169 @@ class CollationStringExpressionsSuite }) } + test("substring check output type on explicitly collated string") { + case class SubstringTestCase[R](args: Seq[String], collation: String, result: R) + val checks = Seq( + SubstringTestCase(Seq("Spark", "2"), "UTF8_BINARY", "park"), + SubstringTestCase(Seq("Spark", "2"), "UTF8_BINARY_LCASE", "park") + ) + checks.foreach(ct => { + val query = s"SELECT substr(collate('${ct.args.head}', '${ct.collation}')," + + s" ${ct.args.tail.head})" + // Result & data type + checkAnswer(sql(query), Row(ct.result)) + assert(sql(query).schema.fields.head.dataType.sameType(StringType(ct.collation))) + }) + } + + test("left/right/substr on implicitly collated string returns proper value and type") { + case class QTestCase(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( + QTestCase(s"select left(left('$longString' collate " + c + ", 5), 1)", c, Row("I")), + QTestCase(s"select right(right('$longString' collate " + c + ", 5), 1)", c, Row("s")), + QTestCase( + 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))) + } + } + + test("left/right/substr on explicitly collated proper string returns proper value and type") { Review Comment: With this, "substring check output type on explicitly collated string" seems unnecessary? -- 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