uros-db commented on code in PR #46040:
URL: https://github.com/apache/spark/pull/46040#discussion_r1565608369


##########
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:
   in other words, let's just look from the outside at string expression like a 
black box module, and focus just on making it work with collations properly
   
   otherwise, we might end up with too many repetitive tests



-- 
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

Reply via email to